comparison src/http/ngx_http_request.c @ 395:f8f0f1834266

nginx-0.0.7-2004-07-16-21:11:43 import
author Igor Sysoev <igor@sysoev.ru>
date Fri, 16 Jul 2004 17:11:43 +0000
parents e7a68e14ccd3
children 6f3b20c1ac50
comparison
equal deleted inserted replaced
394:e7a68e14ccd3 395:f8f0f1834266
4 #include <ngx_event.h> 4 #include <ngx_event.h>
5 #include <ngx_http.h> 5 #include <ngx_http.h>
6 6
7 7
8 static void ngx_http_init_request(ngx_event_t *ev); 8 static void ngx_http_init_request(ngx_event_t *ev);
9 #if (NGX_HTTP_SSL)
10 static void ngx_http_check_ssl_handshake(ngx_event_t *rev);
11 #endif
9 static void ngx_http_process_request_line(ngx_event_t *rev); 12 static void ngx_http_process_request_line(ngx_event_t *rev);
10 static void ngx_http_process_request_headers(ngx_event_t *rev); 13 static void ngx_http_process_request_headers(ngx_event_t *rev);
11 static ssize_t ngx_http_read_request_header(ngx_http_request_t *r); 14 static ssize_t ngx_http_read_request_header(ngx_http_request_t *r);
12 static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r); 15 static ngx_int_t ngx_http_process_request_header(ngx_http_request_t *r);
13 16
38 "client %s sent invalid header, URL: %s", 41 "client %s sent invalid header, URL: %s",
39 "client %s sent too long header line, URL: %s", 42 "client %s sent too long header line, URL: %s",
40 "client %s sent HTTP/1.1 request without \"Host\" header, URL: %s", 43 "client %s sent HTTP/1.1 request without \"Host\" header, URL: %s",
41 "client %s sent invalid \"Content-Length\" header, URL: %s", 44 "client %s sent invalid \"Content-Length\" header, URL: %s",
42 "client %s sent POST method without \"Content-Length\" header, URL: %s", 45 "client %s sent POST method without \"Content-Length\" header, URL: %s",
46 "client %s sent plain HTTP request to HTTPS port, URL: %s",
43 "client %s sent invalid \"Host\" header \"%s\", URL: %s" 47 "client %s sent invalid \"Host\" header \"%s\", URL: %s"
44 }; 48 };
45 49
46 50
47 #if 0 51 #if 0
230 234
231 r->main_conf = cscf->ctx->main_conf; 235 r->main_conf = cscf->ctx->main_conf;
232 r->srv_conf = cscf->ctx->srv_conf; 236 r->srv_conf = cscf->ctx->srv_conf;
233 r->loc_conf = cscf->ctx->loc_conf; 237 r->loc_conf = cscf->ctx->loc_conf;
234 238
239 rev->event_handler = ngx_http_process_request_line;
240
241 r->recv = ngx_recv;
242 r->send_chain = ngx_send_chain;
243
235 #if (NGX_HTTP_SSL) 244 #if (NGX_HTTP_SSL)
236 245
237 sscf = ngx_http_get_module_srv_conf(r, ngx_http_ssl_filter_module); 246 sscf = ngx_http_get_module_srv_conf(r, ngx_http_ssl_module);
238 if (sscf->enable) { 247 if (sscf->enable) {
239 if (ngx_ssl_create_session(sscf->ssl_ctx, c) == NGX_ERROR) { 248 if (ngx_ssl_create_session(sscf->ssl_ctx, c, NGX_SSL_BUFFER)
249 == NGX_ERROR)
250 {
240 ngx_http_close_connection(c); 251 ngx_http_close_connection(c);
241 return; 252 return;
242 } 253 }
243 254
244 r->filter_need_in_memory = 1; 255 r->filter_need_in_memory = 1;
256 rev->event_handler = ngx_http_check_ssl_handshake;
245 } 257 }
246 258
247 #endif 259 #endif
248 260
249 server_name = cscf->server_names.elts; 261 server_name = cscf->server_names.elts;
319 r->headers_out.content_length_n = -1; 331 r->headers_out.content_length_n = -1;
320 r->headers_out.last_modified_time = -1; 332 r->headers_out.last_modified_time = -1;
321 333
322 r->http_state = NGX_HTTP_READING_REQUEST_STATE; 334 r->http_state = NGX_HTTP_READING_REQUEST_STATE;
323 335
336 rev->event_handler(rev);
337 }
338
339
340 #if (NGX_HTTP_SSL)
341
342 static void ngx_http_check_ssl_handshake(ngx_event_t *rev)
343 {
344 int n;
345 u_char buf[1];
346 ngx_connection_t *c;
347 ngx_http_request_t *r;
348
349 c = rev->data;
350 r = c->data;
351
352 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0,
353 "http check ssl handshake");
354
355 if (rev->timedout) {
356 ngx_http_client_error(r, 0, NGX_HTTP_REQUEST_TIME_OUT);
357 return;
358 }
359
360 n = recv(c->fd, buf, 1, MSG_PEEK);
361
362 if (n == -1 && ngx_socket_errno == NGX_EAGAIN) {
363 return;
364 }
365
366 if (n == 1) {
367 if (buf[0] == 0x80 /* SSLv2 */ || buf[0] == 0x16 /* SSLv3/TLSv1 */) {
368 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, rev->log, 0,
369 "https ssl handshake: 0x%X", buf[0]);
370
371 r->recv = ngx_ssl_recv;
372 r->send_chain = ngx_ssl_send_chain;
373
374 } else {
375 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0,
376 "plain http");
377
378 r->plain_http = 1;
379 }
380 }
381
324 rev->event_handler = ngx_http_process_request_line; 382 rev->event_handler = ngx_http_process_request_line;
325 ngx_http_process_request_line(rev); 383 ngx_http_process_request_line(rev);
326 } 384 }
385
386 #endif
327 387
328 388
329 static void ngx_http_process_request_line(ngx_event_t *rev) 389 static void ngx_http_process_request_line(ngx_event_t *rev)
330 { 390 {
331 u_char *p; 391 u_char *p;
830 890
831 if (!rev->ready) { 891 if (!rev->ready) {
832 return NGX_AGAIN; 892 return NGX_AGAIN;
833 } 893 }
834 894
835 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); 895 n = r->recv(r->connection, r->header_in->last,
836 896 r->header_in->end - r->header_in->last);
837 n = cscf->recv(r->connection, r->header_in->last,
838 r->header_in->end - r->header_in->last);
839 897
840 if (n == NGX_AGAIN) { 898 if (n == NGX_AGAIN) {
841 if (!r->header_timeout_set) { 899 if (!r->header_timeout_set) {
900 cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
842 ngx_add_timer(rev, cscf->client_header_timeout); 901 ngx_add_timer(rev, cscf->client_header_timeout);
843 r->header_timeout_set = 1; 902 r->header_timeout_set = 1;
844 } 903 }
845 904
846 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { 905 if (ngx_handle_read_event(rev, 0) == NGX_ERROR) {
935 } 994 }
936 } 995 }
937 996
938 if (r->method == NGX_HTTP_POST && r->headers_in.content_length_n <= 0) { 997 if (r->method == NGX_HTTP_POST && r->headers_in.content_length_n <= 0) {
939 return NGX_HTTP_PARSE_POST_WO_CL_HEADER; 998 return NGX_HTTP_PARSE_POST_WO_CL_HEADER;
999 }
1000
1001 if (r->plain_http) {
1002 return NGX_HTTP_PARSE_HTTP_TO_HTTPS;
940 } 1003 }
941 1004
942 if (r->headers_in.connection) { 1005 if (r->headers_in.connection) {
943 if (r->headers_in.connection->value.len == 5 1006 if (r->headers_in.connection->value.len == 5
944 && ngx_strcasecmp(r->headers_in.connection->value.data, "close") 1007 && ngx_strcasecmp(r->headers_in.connection->value.data, "close")
1871 } 1934 }
1872 1935
1873 r->connection->log->handler = NULL; 1936 r->connection->log->handler = NULL;
1874 1937
1875 if (ctx->url) { 1938 if (ctx->url) {
1876 if (client_error == NGX_HTTP_PARSE_INVALID_HOST) { 1939 switch (client_error) {
1940
1941 case NGX_HTTP_PARSE_INVALID_HOST:
1877 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, 1942 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1878 client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR], 1943 client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR],
1879 ctx->client, r->headers_in.host->value.data, ctx->url); 1944 ctx->client, r->headers_in.host->value.data, ctx->url);
1880 1945
1881 error = NGX_HTTP_INVALID_HOST; 1946 error = NGX_HTTP_INVALID_HOST;
1886 ngx_http_close_request(r, error); 1951 ngx_http_close_request(r, error);
1887 ngx_http_close_connection(r->connection); 1952 ngx_http_close_connection(r->connection);
1888 return; 1953 return;
1889 } 1954 }
1890 1955
1891 } else { 1956 break;
1957
1958 case NGX_HTTP_PARSE_HTTP_TO_HTTPS:
1959 error = NGX_HTTP_TO_HTTPS;
1960
1961 /* fall through */
1962
1963 default:
1892 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, 1964 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1893 client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR], 1965 client_header_errors[client_error - NGX_HTTP_CLIENT_ERROR],
1894 ctx->client, ctx->url); 1966 ctx->client, ctx->url);
1895 } 1967 }
1896 1968