0
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
|
4 */
|
|
5
|
|
6
|
|
7 #include <ngx_config.h>
|
|
8 #include <ngx_core.h>
|
|
9 #include <ngx_http.h>
|
|
10
|
|
11
|
58
|
12 static void ngx_http_read_client_request_body_handler(ngx_http_request_t *r);
|
|
13 static ngx_int_t ngx_http_do_read_client_request_body(ngx_http_request_t *r);
|
182
|
14 static ngx_int_t ngx_http_write_request_body(ngx_http_request_t *r,
|
|
15 ngx_chain_t *body);
|
326
|
16 static ngx_int_t ngx_http_read_discarded_request_body(ngx_http_request_t *r);
|
438
|
17 static ngx_int_t ngx_http_test_expect(ngx_http_request_t *r);
|
182
|
18
|
0
|
19
|
28
|
20 /*
|
|
21 * on completion ngx_http_read_client_request_body() adds to
|
|
22 * r->request_body->bufs one or two bufs:
|
|
23 * *) one memory buf that was preread in r->header_in;
|
|
24 * *) one memory or file buf that contains the rest of the body
|
|
25 */
|
0
|
26
|
50
|
27 ngx_int_t
|
|
28 ngx_http_read_client_request_body(ngx_http_request_t *r,
|
|
29 ngx_http_client_body_handler_pt post_handler)
|
0
|
30 {
|
212
|
31 size_t preread;
|
|
32 ssize_t size;
|
0
|
33 ngx_buf_t *b;
|
182
|
34 ngx_chain_t *cl, **next;
|
238
|
35 ngx_temp_file_t *tf;
|
28
|
36 ngx_http_request_body_t *rb;
|
0
|
37 ngx_http_core_loc_conf_t *clcf;
|
|
38
|
518
|
39 r->main->count++;
|
|
40
|
86
|
41 if (r->request_body || r->discard_body) {
|
58
|
42 post_handler(r);
|
|
43 return NGX_OK;
|
|
44 }
|
|
45
|
438
|
46 if (ngx_http_test_expect(r) != NGX_OK) {
|
|
47 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
48 }
|
|
49
|
50
|
50 rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t));
|
|
51 if (rb == NULL) {
|
28
|
52 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
53 }
|
|
54
|
|
55 r->request_body = rb;
|
|
56
|
238
|
57 if (r->headers_in.content_length_n < 0) {
|
|
58 post_handler(r);
|
|
59 return NGX_OK;
|
|
60 }
|
|
61
|
|
62 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
63
|
|
64 if (r->headers_in.content_length_n == 0) {
|
|
65
|
|
66 if (r->request_body_in_file_only) {
|
|
67 tf = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t));
|
|
68 if (tf == NULL) {
|
|
69 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
70 }
|
|
71
|
|
72 tf->file.fd = NGX_INVALID_FILE;
|
|
73 tf->file.log = r->connection->log;
|
|
74 tf->path = clcf->client_body_temp_path;
|
|
75 tf->pool = r->pool;
|
|
76 tf->warn = "a client request body is buffered to a temporary file";
|
|
77 tf->log_level = r->request_body_file_log_level;
|
|
78 tf->persistent = r->request_body_in_persistent_file;
|
278
|
79 tf->clean = r->request_body_in_clean_file;
|
238
|
80
|
|
81 if (r->request_body_file_group_access) {
|
276
|
82 tf->access = 0660;
|
238
|
83 }
|
|
84
|
|
85 rb->temp_file = tf;
|
|
86
|
|
87 if (ngx_create_temp_file(&tf->file, tf->path, tf->pool,
|
278
|
88 tf->persistent, tf->clean, tf->access)
|
238
|
89 != NGX_OK)
|
|
90 {
|
|
91 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
92 }
|
|
93 }
|
|
94
|
28
|
95 post_handler(r);
|
318
|
96
|
28
|
97 return NGX_OK;
|
|
98 }
|
|
99
|
|
100 rb->post_handler = post_handler;
|
|
101
|
|
102 /*
|
|
103 * set by ngx_pcalloc():
|
|
104 *
|
|
105 * rb->bufs = NULL;
|
|
106 * rb->buf = NULL;
|
|
107 * rb->rest = 0;
|
|
108 */
|
|
109
|
182
|
110 preread = r->header_in->last - r->header_in->pos;
|
0
|
111
|
182
|
112 if (preread) {
|
0
|
113
|
|
114 /* there is the pre-read part of the request body */
|
|
115
|
182
|
116 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
117 "http client request body preread %uz", preread);
|
|
118
|
50
|
119 b = ngx_calloc_buf(r->pool);
|
|
120 if (b == NULL) {
|
28
|
121 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
122 }
|
0
|
123
|
|
124 b->temporary = 1;
|
182
|
125 b->start = r->header_in->pos;
|
|
126 b->pos = r->header_in->pos;
|
|
127 b->last = r->header_in->last;
|
|
128 b->end = r->header_in->end;
|
0
|
129
|
50
|
130 rb->bufs = ngx_alloc_chain_link(r->pool);
|
|
131 if (rb->bufs == NULL) {
|
28
|
132 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
133 }
|
|
134
|
|
135 rb->bufs->buf = b;
|
|
136 rb->bufs->next = NULL;
|
0
|
137
|
216
|
138 rb->buf = b;
|
|
139
|
214
|
140 if ((off_t) preread >= r->headers_in.content_length_n) {
|
0
|
141
|
|
142 /* the whole request body was pre-read */
|
|
143
|
212
|
144 r->header_in->pos += (size_t) r->headers_in.content_length_n;
|
24
|
145 r->request_length += r->headers_in.content_length_n;
|
634
|
146 b->last = r->header_in->pos;
|
0
|
147
|
182
|
148 if (r->request_body_in_file_only) {
|
|
149 if (ngx_http_write_request_body(r, rb->bufs) != NGX_OK) {
|
|
150 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
151 }
|
|
152 }
|
|
153
|
28
|
154 post_handler(r);
|
0
|
155
|
|
156 return NGX_OK;
|
|
157 }
|
|
158
|
182
|
159 /*
|
|
160 * to not consider the body as pipelined request in
|
|
161 * ngx_http_set_keepalive()
|
|
162 */
|
0
|
163 r->header_in->pos = r->header_in->last;
|
182
|
164
|
|
165 r->request_length += preread;
|
|
166
|
|
167 rb->rest = r->headers_in.content_length_n - preread;
|
|
168
|
214
|
169 if (rb->rest <= (off_t) (b->end - b->last)) {
|
182
|
170
|
|
171 /* the whole request body may be placed in r->header_in */
|
|
172
|
276
|
173 rb->to_write = rb->bufs;
|
|
174
|
182
|
175 r->read_event_handler = ngx_http_read_client_request_body_handler;
|
|
176
|
|
177 return ngx_http_do_read_client_request_body(r);
|
|
178 }
|
|
179
|
|
180 next = &rb->bufs->next;
|
|
181
|
|
182 } else {
|
|
183 b = NULL;
|
|
184 rb->rest = r->headers_in.content_length_n;
|
|
185 next = &rb->bufs;
|
0
|
186 }
|
|
187
|
182
|
188 size = clcf->client_body_buffer_size;
|
|
189 size += size >> 2;
|
0
|
190
|
212
|
191 if (rb->rest < size) {
|
|
192 size = (ssize_t) rb->rest;
|
0
|
193
|
182
|
194 if (r->request_body_in_single_buf) {
|
|
195 size += preread;
|
|
196 }
|
|
197
|
0
|
198 } else {
|
|
199 size = clcf->client_body_buffer_size;
|
182
|
200
|
|
201 /* disable copying buffer for r->request_body_in_single_buf */
|
|
202 b = NULL;
|
0
|
203 }
|
|
204
|
50
|
205 rb->buf = ngx_create_temp_buf(r->pool, size);
|
|
206 if (rb->buf == NULL) {
|
28
|
207 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
208 }
|
0
|
209
|
50
|
210 cl = ngx_alloc_chain_link(r->pool);
|
|
211 if (cl == NULL) {
|
28
|
212 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
213 }
|
0
|
214
|
28
|
215 cl->buf = rb->buf;
|
|
216 cl->next = NULL;
|
|
217
|
182
|
218 if (b && r->request_body_in_single_buf) {
|
|
219 size = b->last - b->pos;
|
|
220 ngx_memcpy(rb->buf->pos, b->pos, size);
|
|
221 rb->buf->last += size;
|
|
222
|
|
223 next = &rb->bufs;
|
|
224 }
|
|
225
|
|
226 *next = cl;
|
|
227
|
|
228 if (r->request_body_in_file_only || r->request_body_in_single_buf) {
|
|
229 rb->to_write = rb->bufs;
|
0
|
230
|
|
231 } else {
|
182
|
232 rb->to_write = rb->bufs->next ? rb->bufs->next : rb->bufs;
|
0
|
233 }
|
|
234
|
58
|
235 r->read_event_handler = ngx_http_read_client_request_body_handler;
|
0
|
236
|
58
|
237 return ngx_http_do_read_client_request_body(r);
|
0
|
238 }
|
|
239
|
|
240
|
50
|
241 static void
|
58
|
242 ngx_http_read_client_request_body_handler(ngx_http_request_t *r)
|
0
|
243 {
|
58
|
244 ngx_int_t rc;
|
0
|
245
|
58
|
246 if (r->connection->read->timedout) {
|
126
|
247 r->connection->timedout = 1;
|
278
|
248 ngx_http_finalize_request(r, NGX_HTTP_REQUEST_TIME_OUT);
|
0
|
249 return;
|
|
250 }
|
|
251
|
58
|
252 rc = ngx_http_do_read_client_request_body(r);
|
0
|
253
|
|
254 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
|
278
|
255 ngx_http_finalize_request(r, rc);
|
0
|
256 }
|
|
257 }
|
|
258
|
|
259
|
50
|
260 static ngx_int_t
|
58
|
261 ngx_http_do_read_client_request_body(ngx_http_request_t *r)
|
0
|
262 {
|
|
263 size_t size;
|
|
264 ssize_t n;
|
|
265 ngx_buf_t *b;
|
58
|
266 ngx_connection_t *c;
|
28
|
267 ngx_http_request_body_t *rb;
|
0
|
268 ngx_http_core_loc_conf_t *clcf;
|
|
269
|
58
|
270 c = r->connection;
|
28
|
271 rb = r->request_body;
|
0
|
272
|
|
273 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
|
|
274 "http read client request body");
|
|
275
|
|
276 for ( ;; ) {
|
256
|
277 for ( ;; ) {
|
|
278 if (rb->buf->last == rb->buf->end) {
|
|
279
|
|
280 if (ngx_http_write_request_body(r, rb->to_write) != NGX_OK) {
|
|
281 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
282 }
|
28
|
283
|
256
|
284 rb->to_write = rb->bufs->next ? rb->bufs->next : rb->bufs;
|
|
285 rb->buf->last = rb->buf->start;
|
|
286 }
|
|
287
|
|
288 size = rb->buf->end - rb->buf->last;
|
|
289
|
|
290 if ((off_t) size > rb->rest) {
|
|
291 size = (size_t) rb->rest;
|
0
|
292 }
|
|
293
|
256
|
294 n = c->recv(c, rb->buf->last, size);
|
|
295
|
|
296 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
|
|
297 "http client request body recv %z", n);
|
0
|
298
|
256
|
299 if (n == NGX_AGAIN) {
|
|
300 break;
|
|
301 }
|
|
302
|
|
303 if (n == 0) {
|
|
304 ngx_log_error(NGX_LOG_INFO, c->log, 0,
|
|
305 "client closed prematurely connection");
|
|
306 }
|
0
|
307
|
256
|
308 if (n == 0 || n == NGX_ERROR) {
|
|
309 c->error = 1;
|
|
310 return NGX_HTTP_BAD_REQUEST;
|
|
311 }
|
|
312
|
|
313 rb->buf->last += n;
|
|
314 rb->rest -= n;
|
|
315 r->request_length += n;
|
|
316
|
|
317 if (rb->rest == 0) {
|
|
318 break;
|
|
319 }
|
|
320
|
|
321 if (rb->buf->last < rb->buf->end) {
|
|
322 break;
|
|
323 }
|
0
|
324 }
|
|
325
|
|
326 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
|
286
|
327 "http client request body rest %O", rb->rest);
|
0
|
328
|
28
|
329 if (rb->rest == 0) {
|
0
|
330 break;
|
|
331 }
|
|
332
|
256
|
333 if (!c->read->ready) {
|
|
334 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
335 ngx_add_timer(c->read, clcf->client_body_timeout);
|
0
|
336
|
430
|
337 if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
|
256
|
338 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
339 }
|
122
|
340
|
256
|
341 return NGX_AGAIN;
|
122
|
342 }
|
0
|
343 }
|
|
344
|
122
|
345 if (c->read->timer_set) {
|
|
346 ngx_del_timer(c->read);
|
|
347 }
|
|
348
|
182
|
349 if (rb->temp_file || r->request_body_in_file_only) {
|
0
|
350
|
|
351 /* save the last part */
|
28
|
352
|
182
|
353 if (ngx_http_write_request_body(r, rb->to_write) != NGX_OK) {
|
0
|
354 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
355 }
|
|
356
|
50
|
357 b = ngx_calloc_buf(r->pool);
|
|
358 if (b == NULL) {
|
0
|
359 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
360 }
|
|
361
|
|
362 b->in_file = 1;
|
|
363 b->file_pos = 0;
|
28
|
364 b->file_last = rb->temp_file->file.offset;
|
|
365 b->file = &rb->temp_file->file;
|
0
|
366
|
28
|
367 if (rb->bufs->next) {
|
|
368 rb->bufs->next->buf = b;
|
0
|
369
|
|
370 } else {
|
28
|
371 rb->bufs->buf = b;
|
0
|
372 }
|
|
373 }
|
|
374
|
634
|
375 if (rb->bufs->next
|
|
376 && (r->request_body_in_file_only || r->request_body_in_single_buf))
|
|
377 {
|
182
|
378 rb->bufs = rb->bufs->next;
|
|
379 }
|
|
380
|
636
|
381 r->read_event_handler = ngx_http_block_reading;
|
|
382
|
28
|
383 rb->post_handler(r);
|
0
|
384
|
|
385 return NGX_OK;
|
|
386 }
|
182
|
387
|
|
388
|
|
389 static ngx_int_t
|
|
390 ngx_http_write_request_body(ngx_http_request_t *r, ngx_chain_t *body)
|
|
391 {
|
|
392 ssize_t n;
|
|
393 ngx_temp_file_t *tf;
|
|
394 ngx_http_request_body_t *rb;
|
|
395 ngx_http_core_loc_conf_t *clcf;
|
|
396
|
|
397 rb = r->request_body;
|
|
398
|
|
399 if (rb->temp_file == NULL) {
|
|
400 tf = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t));
|
|
401 if (tf == NULL) {
|
|
402 return NGX_ERROR;
|
|
403 }
|
|
404
|
|
405 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
406
|
|
407 tf->file.fd = NGX_INVALID_FILE;
|
|
408 tf->file.log = r->connection->log;
|
|
409 tf->path = clcf->client_body_temp_path;
|
|
410 tf->pool = r->pool;
|
|
411 tf->warn = "a client request body is buffered to a temporary file";
|
186
|
412 tf->log_level = r->request_body_file_log_level;
|
182
|
413 tf->persistent = r->request_body_in_persistent_file;
|
278
|
414 tf->clean = r->request_body_in_clean_file;
|
182
|
415
|
|
416 if (r->request_body_file_group_access) {
|
276
|
417 tf->access = 0660;
|
182
|
418 }
|
|
419
|
|
420 rb->temp_file = tf;
|
|
421 }
|
|
422
|
|
423 n = ngx_write_chain_to_temp_file(rb->temp_file, body);
|
|
424
|
|
425 /* TODO: n == 0 or not complete and level event */
|
|
426
|
|
427 if (n == NGX_ERROR) {
|
|
428 return NGX_ERROR;
|
|
429 }
|
|
430
|
|
431 rb->temp_file->offset += n;
|
|
432
|
|
433 return NGX_OK;
|
|
434 }
|
|
435
|
|
436
|
|
437 ngx_int_t
|
326
|
438 ngx_http_discard_request_body(ngx_http_request_t *r)
|
182
|
439 {
|
|
440 ssize_t size;
|
|
441 ngx_event_t *rev;
|
|
442
|
222
|
443 if (r != r->main || r->discard_body) {
|
182
|
444 return NGX_OK;
|
|
445 }
|
|
446
|
438
|
447 if (ngx_http_test_expect(r) != NGX_OK) {
|
|
448 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
449 }
|
|
450
|
182
|
451 rev = r->connection->read;
|
|
452
|
|
453 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http set discard body");
|
|
454
|
|
455 if (rev->timer_set) {
|
|
456 ngx_del_timer(rev);
|
|
457 }
|
|
458
|
342
|
459 if (r->headers_in.content_length_n <= 0 || r->request_body) {
|
182
|
460 return NGX_OK;
|
|
461 }
|
|
462
|
|
463 size = r->header_in->last - r->header_in->pos;
|
|
464
|
|
465 if (size) {
|
|
466 if (r->headers_in.content_length_n > size) {
|
538
|
467 r->header_in->pos += size;
|
182
|
468 r->headers_in.content_length_n -= size;
|
|
469
|
|
470 } else {
|
212
|
471 r->header_in->pos += (size_t) r->headers_in.content_length_n;
|
182
|
472 r->headers_in.content_length_n = 0;
|
|
473 return NGX_OK;
|
|
474 }
|
|
475 }
|
|
476
|
538
|
477 r->read_event_handler = ngx_http_discarded_request_body_handler;
|
182
|
478
|
430
|
479 if (ngx_handle_read_event(rev, 0) != NGX_OK) {
|
182
|
480 return NGX_HTTP_INTERNAL_SERVER_ERROR;
|
|
481 }
|
|
482
|
532
|
483 if (ngx_http_read_discarded_request_body(r) == NGX_OK) {
|
|
484 r->lingering_close = 0;
|
|
485
|
|
486 } else {
|
530
|
487 r->count++;
|
532
|
488 r->discard_body = 1;
|
530
|
489 }
|
326
|
490
|
|
491 return NGX_OK;
|
182
|
492 }
|
|
493
|
|
494
|
538
|
495 void
|
|
496 ngx_http_discarded_request_body_handler(ngx_http_request_t *r)
|
182
|
497 {
|
326
|
498 ngx_int_t rc;
|
|
499 ngx_msec_t timer;
|
|
500 ngx_event_t *rev;
|
|
501 ngx_connection_t *c;
|
|
502 ngx_http_core_loc_conf_t *clcf;
|
|
503
|
|
504 c = r->connection;
|
|
505 rev = c->read;
|
182
|
506
|
326
|
507 if (rev->timedout) {
|
|
508 c->timedout = 1;
|
|
509 c->error = 1;
|
538
|
510 ngx_http_finalize_request(r, NGX_ERROR);
|
326
|
511 return;
|
|
512 }
|
182
|
513
|
326
|
514 if (r->lingering_time) {
|
346
|
515 timer = (ngx_msec_t) (r->lingering_time - ngx_time());
|
326
|
516
|
|
517 if (timer <= 0) {
|
|
518 r->discard_body = 0;
|
532
|
519 r->lingering_close = 0;
|
538
|
520 ngx_http_finalize_request(r, NGX_ERROR);
|
182
|
521 return;
|
|
522 }
|
326
|
523
|
|
524 } else {
|
|
525 timer = 0;
|
|
526 }
|
|
527
|
|
528 rc = ngx_http_read_discarded_request_body(r);
|
|
529
|
|
530 if (rc == NGX_OK) {
|
|
531 r->discard_body = 0;
|
532
|
532 r->lingering_close = 0;
|
538
|
533 ngx_http_finalize_request(r, NGX_DONE);
|
326
|
534 return;
|
182
|
535 }
|
|
536
|
326
|
537 /* rc == NGX_AGAIN */
|
|
538
|
430
|
539 if (ngx_handle_read_event(rev, 0) != NGX_OK) {
|
332
|
540 c->error = 1;
|
538
|
541 ngx_http_finalize_request(r, NGX_ERROR);
|
326
|
542 return;
|
|
543 }
|
|
544
|
|
545 if (timer) {
|
|
546
|
|
547 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
|
|
548
|
|
549 timer *= 1000;
|
|
550
|
|
551 if (timer > clcf->lingering_timeout) {
|
|
552 timer = clcf->lingering_timeout;
|
|
553 }
|
|
554
|
|
555 ngx_add_timer(rev, timer);
|
182
|
556 }
|
|
557 }
|
|
558
|
|
559
|
|
560 static ngx_int_t
|
326
|
561 ngx_http_read_discarded_request_body(ngx_http_request_t *r)
|
182
|
562 {
|
212
|
563 size_t size;
|
|
564 ssize_t n;
|
182
|
565 u_char buffer[NGX_HTTP_DISCARD_BUFFER_SIZE];
|
|
566
|
|
567 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
568 "http read discarded body");
|
|
569
|
530
|
570 for ( ;; ) {
|
326
|
571 if (r->headers_in.content_length_n == 0) {
|
|
572 r->read_event_handler = ngx_http_block_reading;
|
|
573 return NGX_OK;
|
|
574 }
|
182
|
575
|
530
|
576 if (!r->connection->read->ready) {
|
|
577 return NGX_AGAIN;
|
|
578 }
|
|
579
|
326
|
580 size = (r->headers_in.content_length_n > NGX_HTTP_DISCARD_BUFFER_SIZE) ?
|
|
581 NGX_HTTP_DISCARD_BUFFER_SIZE:
|
|
582 (size_t) r->headers_in.content_length_n;
|
182
|
583
|
326
|
584 n = r->connection->recv(r->connection, buffer, size);
|
182
|
585
|
326
|
586 if (n == NGX_ERROR) {
|
|
587 r->connection->error = 1;
|
|
588 return NGX_OK;
|
|
589 }
|
182
|
590
|
326
|
591 if (n == NGX_AGAIN) {
|
|
592 return NGX_AGAIN;
|
|
593 }
|
182
|
594
|
330
|
595 if (n == 0) {
|
|
596 return NGX_OK;
|
|
597 }
|
|
598
|
326
|
599 r->headers_in.content_length_n -= n;
|
530
|
600 }
|
182
|
601 }
|
438
|
602
|
|
603
|
|
604 static ngx_int_t
|
|
605 ngx_http_test_expect(ngx_http_request_t *r)
|
|
606 {
|
|
607 ngx_int_t n;
|
|
608 ngx_str_t *expect;
|
|
609
|
|
610 if (r->expect_tested
|
|
611 || r->headers_in.expect == NULL
|
|
612 || r->http_version < NGX_HTTP_VERSION_11)
|
|
613 {
|
|
614 return NGX_OK;
|
|
615 }
|
|
616
|
|
617 r->expect_tested = 1;
|
|
618
|
|
619 expect = &r->headers_in.expect->value;
|
|
620
|
|
621 if (expect->len != sizeof("100-continue") - 1
|
|
622 || ngx_strncasecmp(expect->data, (u_char *) "100-continue",
|
|
623 sizeof("100-continue") - 1)
|
|
624 != 0)
|
|
625 {
|
|
626 return NGX_OK;
|
|
627 }
|
|
628
|
|
629 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
|
630 "send 100 Continue");
|
|
631
|
|
632 n = r->connection->send(r->connection,
|
|
633 (u_char *) "HTTP/1.1 100 Continue" CRLF CRLF,
|
|
634 sizeof("HTTP/1.1 100 Continue" CRLF CRLF) - 1);
|
|
635
|
|
636 if (n == sizeof("HTTP/1.1 100 Continue" CRLF CRLF) - 1) {
|
|
637 return NGX_OK;
|
|
638 }
|
|
639
|
|
640 /* we assume that such small packet should be send successfully */
|
|
641
|
|
642 return NGX_ERROR;
|
|
643 }
|