src/server/daemon/httprequest.c

changeset 193
aa8393527b1e
parent 180
98462e878ca7
parent 191
391ccd490d97
child 211
2160585200ac
equal deleted inserted replaced
183:f33974f0dce0 193:aa8393527b1e
38 #include "../util/io.h" 38 #include "../util/io.h"
39 #include "../util/util.h" 39 #include "../util/util.h"
40 #include "httprequest.h" 40 #include "httprequest.h"
41 #include "config.h" 41 #include "config.h"
42 #include "vserver.h" 42 #include "vserver.h"
43 #include "event.h"
43 #include "httplistener.h" 44 #include "httplistener.h"
44 #include "func.h" 45 #include "func.h"
45 #include "error.h" 46 #include "error.h"
46 47
47 void http_request_init(HTTPRequest *req) { 48 void http_request_init(HTTPRequest *req) {
84 } 85 }
85 86
86 return S("/"); 87 return S("/");
87 } 88 }
88 89
89 int handle_request(HTTPRequest *request, threadpool_t *thrpool) { 90 int handle_request(HTTPRequest *request, threadpool_t *thrpool, EventHandler *ev) {
90 // handle nsapi request 91 // handle nsapi request
91 92
92 // create pool 93 // create pool
93 pool_handle_t *pool = pool_create(); 94 pool_handle_t *pool = pool_create();
94 95
108 109
109 // fill session structure 110 // fill session structure
110 sn->connection = request->connection; 111 sn->connection = request->connection;
111 sn->netbuf = request->netbuf; 112 sn->netbuf = request->netbuf;
112 sn->sn.pool = pool; 113 sn->sn.pool = pool;
113 //sn->sn.csd = stream_new_from_fd(pool, request->connection->fd); 114 SessionHandler *sh = request->connection->session_handler;
114 //sn->sn.csd = net_stream_from_fd(pool, request->connection->fd); 115 WSBool ssl;
115 IOStream *io; 116 IOStream *io = sh->create_iostream(sh, request->connection, pool, &ssl);
116 if(request->connection->ssl) {
117 io = sslstream_new(pool, request->connection->ssl);
118 sn->sn.ssl = 1;
119 } else {
120 io = sysstream_new(pool, request->connection->fd);
121 }
122 sn->sn.csd = httpstream_new(pool, io); 117 sn->sn.csd = httpstream_new(pool, io);
123 118 sn->sn.ssl = ssl;
124 119
125 sn->sn.client = pblock_create_pool(sn->sn.pool, 8); 120 sn->sn.client = pblock_create_pool(sn->sn.pool, 8);
126 sn->sn.next = NULL; 121 sn->sn.next = NULL;
127 sn->sn.fill = 1; 122 sn->sn.fill = 1;
128 sn->sn.subject = NULL; 123 sn->sn.subject = NULL;
124
125 if(!ev) {
126 ev = ev_instance(get_default_event_handler());
127 }
128 sn->sn.ev = ev;
129 129
130 // the session needs the current server configuration 130 // the session needs the current server configuration
131 sn->config = request->connection->listener->cfg; 131 sn->config = request->connection->listener->cfg;
132 132
133 // add ip to sn->client pblock 133 // add ip to sn->client pblock

mercurial