Lines Matching refs:r
35 int http_response_buffer_append_authority(request_st * const r, buffer * const o) { in http_response_buffer_append_authority() argument
36 if (!buffer_is_blank(&r->uri.authority)) { in http_response_buffer_append_authority()
37 buffer_append_string_buffer(o, &r->uri.authority); in http_response_buffer_append_authority()
46 if (-1 == getsockname(r->con->fd, (struct sockaddr *)&our_addr, &our_addr_len) in http_response_buffer_append_authority()
48 r->http_status = 500; in http_response_buffer_append_authority()
49 log_perror(r->conf.errh, __FILE__, __LINE__, "can't get sockname"); in http_response_buffer_append_authority()
62 if (0 == sock_addr_nameinfo_append_buffer(o, &our_addr, r->conf.errh)) { in http_response_buffer_append_authority()
77 } else if (!buffer_is_blank(r->server_name)) { in http_response_buffer_append_authority()
78 buffer_append_string_buffer(o, r->server_name); in http_response_buffer_append_authority()
81 if (0 != sock_addr_nameinfo_append_buffer(o, &our_addr, r->conf.errh)) { in http_response_buffer_append_authority()
82 r->http_status = 500; in http_response_buffer_append_authority()
89 if (buffer_is_equal_string(&r->uri.scheme, CONST_STR_LEN("https"))) { in http_response_buffer_append_authority()
92 if (0 == listen_port) listen_port = r->con->srv->srvconf.port; in http_response_buffer_append_authority()
102 int http_response_redirect_to_directory(request_st * const r, int status) { in http_response_redirect_to_directory() argument
103 buffer *o = r->tmp_buf; in http_response_redirect_to_directory()
106 if (r->con->srv->srvconf.absolute_dir_redirect) { in http_response_redirect_to_directory()
107 buffer_append_str2(o, BUF_PTR_LEN(&r->uri.scheme), in http_response_redirect_to_directory()
109 if (0 != http_response_buffer_append_authority(r, o)) { in http_response_redirect_to_directory()
115 r->http_status = status; in http_response_redirect_to_directory()
116 r->resp_body_finished = 1; in http_response_redirect_to_directory()
117 vb = http_header_response_set_ptr(r, HTTP_HEADER_LOCATION, in http_response_redirect_to_directory()
121 vb = http_header_response_set_ptr(r, HTTP_HEADER_CONTENT_LOCATION, in http_response_redirect_to_directory()
125 buffer_append_string_encoded(vb, BUF_PTR_LEN(&r->uri.path), in http_response_redirect_to_directory()
128 if (!buffer_is_blank(&r->uri.query)) in http_response_redirect_to_directory()
130 BUF_PTR_LEN(&r->uri.query)); in http_response_redirect_to_directory()
174 const buffer * http_response_set_last_modified(request_st * const r, const unix_time64_t lmtime) { in http_response_set_last_modified() argument
176 http_header_response_set_ptr(r, HTTP_HEADER_LAST_MODIFIED, in http_response_set_last_modified()
184 static int http_response_maybe_cachable (const request_st * const r) { in http_response_maybe_cachable() argument
185 return (r->rqst_htags in http_response_maybe_cachable()
191 int http_response_handle_cachable(request_st * const r, const buffer *lmod, const unix_time64_t lmt… in http_response_handle_cachable() argument
192 if (!http_response_maybe_cachable(r)) in http_response_handle_cachable()
207 if ((vb = http_header_request_get(r, HTTP_HEADER_IF_NONE_MATCH, in http_response_handle_cachable()
209 && (etag = http_header_response_get(r, HTTP_HEADER_ETAG, in http_response_handle_cachable()
212 int range_request = (0 != light_btst(r->rqst_htags, HTTP_HEADER_RANGE)); in http_response_handle_cachable()
214 if (http_method_get_head_query(r->http_method)) { in http_response_handle_cachable()
215 r->http_status = 304; in http_response_handle_cachable()
218 r->http_status = 412; in http_response_handle_cachable()
219 r->handler_module = NULL; in http_response_handle_cachable()
223 } else if (http_method_get_head_query(r->http_method) in http_response_handle_cachable()
224 && (vb = http_header_request_get(r, HTTP_HEADER_IF_MODIFIED_SINCE, in http_response_handle_cachable()
227 || (lmod = http_header_response_get(r, HTTP_HEADER_LAST_MODIFIED, in http_response_handle_cachable()
232 r->http_status = 304; in http_response_handle_cachable()
241 void http_response_body_clear (request_st * const r, int preserve_length) { in http_response_body_clear() argument
242 r->resp_body_finished = 0; in http_response_body_clear()
243 r->resp_body_started = 0; in http_response_body_clear()
244 r->resp_send_chunked = 0; in http_response_body_clear()
245 r->resp_body_scratchpad = -1; in http_response_body_clear()
246 if (light_btst(r->resp_htags, HTTP_HEADER_TRANSFER_ENCODING)) { in http_response_body_clear()
247 http_header_response_unset(r, HTTP_HEADER_TRANSFER_ENCODING, in http_response_body_clear()
251 if (light_btst(r->resp_htags, HTTP_HEADER_CONTENT_LENGTH)) { in http_response_body_clear()
252 http_header_response_unset(r, HTTP_HEADER_CONTENT_LENGTH, in http_response_body_clear()
256 r->resp_decode_chunked = 0; in http_response_body_clear()
257 if (r->gw_dechunk) { in http_response_body_clear()
258 free(r->gw_dechunk->b.ptr); in http_response_body_clear()
259 free(r->gw_dechunk); in http_response_body_clear()
260 r->gw_dechunk = NULL; in http_response_body_clear()
263 chunkqueue_reset(&r->write_queue); in http_response_body_clear()
267 static void http_response_header_clear (request_st * const r) { in http_response_header_clear() argument
268 r->http_status = 0; in http_response_header_clear()
269 r->resp_htags = 0; in http_response_header_clear()
270 r->resp_header_len = 0; in http_response_header_clear()
271 r->resp_header_repeated = 0; in http_response_header_clear()
272 array_reset_data_strings(&r->resp_headers); in http_response_header_clear()
278 r->resp_send_chunked = 0; in http_response_header_clear()
279 r->resp_decode_chunked = 0; in http_response_header_clear()
280 r->resp_body_scratchpad = -1; in http_response_header_clear()
281 if (r->gw_dechunk) { in http_response_header_clear()
282 free(r->gw_dechunk->b.ptr); in http_response_header_clear()
283 free(r->gw_dechunk); in http_response_header_clear()
284 r->gw_dechunk = NULL; in http_response_header_clear()
289 void http_response_reset (request_st * const r) { in http_response_reset() argument
290 r->http_status = 0; in http_response_reset()
291 r->con->is_writable = 1; in http_response_reset()
292 r->handler_module = NULL; in http_response_reset()
293 if (r->physical.path.ptr) { /*(skip for mod_fastcgi authorizer)*/ in http_response_reset()
294 buffer_clear(&r->physical.doc_root); in http_response_reset()
295 buffer_clear(&r->physical.basedir); in http_response_reset()
296 buffer_reset(&r->physical.path); in http_response_reset()
297 buffer_reset(&r->physical.rel_path); in http_response_reset()
299 r->resp_htags = 0; in http_response_reset()
300 r->resp_header_len = 0; in http_response_reset()
301 r->resp_header_repeated = 0; in http_response_reset()
302 array_reset_data_strings(&r->resp_headers); in http_response_reset()
303 http_response_body_clear(r, 0); in http_response_reset()
307 handler_t http_response_reqbody_read_error (request_st * const r, int http_status) { in http_response_reqbody_read_error() argument
308 r->keep_alive = 0; in http_response_reqbody_read_error()
311 if (0 != r->resp_header_len) return HANDLER_ERROR; in http_response_reqbody_read_error()
313 http_response_body_clear(r, 0); in http_response_reqbody_read_error()
314 r->http_status = http_status; in http_response_reqbody_read_error()
315 r->handler_module = NULL; in http_response_reqbody_read_error()
320 void http_response_send_file (request_st * const r, const buffer * const path, stat_cache_entry *sc… in http_response_send_file() argument
323 sce = stat_cache_get_entry_open(path, r->conf.follow_symlink); in http_response_send_file()
325 r->http_status = (errno == ENOENT) ? 404 : 403; in http_response_send_file()
326 log_error(r->conf.errh, __FILE__, __LINE__, in http_response_send_file()
327 "not a regular file: %s -> %s", r->uri.path.ptr, path->ptr); in http_response_send_file()
331 r->http_status = (errno == ENOENT) ? 404 : 403; in http_response_send_file()
332 if (r->conf.log_request_handling) { in http_response_send_file()
333 log_perror(r->conf.errh, __FILE__, __LINE__, in http_response_send_file()
340 if (__builtin_expect( (!r->conf.follow_symlink), 0) in http_response_send_file()
341 && 0 != stat_cache_path_contains_symlink(path, r->conf.errh)) { in http_response_send_file()
342 r->http_status = 403; in http_response_send_file()
343 if (r->conf.log_request_handling) { in http_response_send_file()
344 log_error(r->conf.errh, __FILE__, __LINE__, in http_response_send_file()
346 log_error(r->conf.errh, __FILE__, __LINE__, in http_response_send_file()
354 r->http_status = 403; in http_response_send_file()
355 if (r->conf.log_file_not_found) { in http_response_send_file()
356 log_error(r->conf.errh, __FILE__, __LINE__, in http_response_send_file()
358 r->uri.path.ptr, path->ptr); in http_response_send_file()
367 if (__builtin_expect( (!light_btst(r->resp_htags, HTTP_HEADER_CONTENT_TYPE)), 1)) { in http_response_send_file()
368 content_type = stat_cache_content_type_get(sce, r); in http_response_send_file()
372 http_header_response_set(r, HTTP_HEADER_CONTENT_TYPE, in http_response_send_file()
381 && (0 == r->http_status || 200 == r->http_status); in http_response_send_file()
383 if (__builtin_expect( (!light_btst(r->resp_htags, HTTP_HEADER_ETAG)), 1) in http_response_send_file()
384 && 0 != r->conf.etag_flags) { in http_response_send_file()
386 stat_cache_etag_get(sce, r->conf.etag_flags); in http_response_send_file()
388 http_header_response_set(r, HTTP_HEADER_ETAG, in http_response_send_file()
395 __builtin_expect( (!light_btst(r->resp_htags, HTTP_HEADER_LAST_MODIFIED)), 1) in http_response_send_file()
396 ? http_response_set_last_modified(r, sce->st.st_mtime) in http_response_send_file()
399 if (http_response_maybe_cachable(r) in http_response_send_file()
400 && HANDLER_FINISHED == http_response_handle_cachable(r, lmod, sce->st.st_mtime)) in http_response_send_file()
410 if (0 == sce->st.st_size || 0 == http_chunk_append_file_ref(r, sce)) { in http_response_send_file()
411 r->http_status = 200; in http_response_send_file()
412 r->resp_body_finished = 1; in http_response_send_file()
415 http_header_response_set_ptr(r, HTTP_HEADER_CONTENT_LENGTH, in http_response_send_file()
420 r->http_status = 500; in http_response_send_file()
425 static void http_response_xsendfile (request_st * const r, buffer * const path, const array * const… in http_response_xsendfile() argument
426 const int status = r->http_status; in http_response_xsendfile()
433 if (light_btst(r->resp_htags, HTTP_HEADER_CONTENT_LENGTH)) { in http_response_xsendfile()
434 http_header_response_unset(r, HTTP_HEADER_CONTENT_LENGTH, in http_response_xsendfile()
440 log_error(r->conf.errh, __FILE__, __LINE__, in http_response_xsendfile()
442 if (r->http_status < 400) { in http_response_xsendfile()
443 r->http_status = 502; in http_response_xsendfile()
444 r->handler_module = NULL; in http_response_xsendfile()
449 if (r->conf.force_lowercase_filenames) { in http_response_xsendfile()
453 r->http_status = 502; in http_response_xsendfile()
462 const buffer * const xval = !r->conf.force_lowercase_filenames in http_response_xsendfile()
466 log_error(r->conf.errh, __FILE__, __LINE__, in http_response_xsendfile()
468 r->http_status = 403; in http_response_xsendfile()
473 if (valid) http_response_send_file(r, path, NULL); in http_response_xsendfile()
475 if (r->http_status >= 400 && status < 300) { in http_response_xsendfile()
476 r->handler_module = NULL; in http_response_xsendfile()
478 r->http_status = status; in http_response_xsendfile()
483 static void http_response_xsendfile2(request_st * const r, const buffer * const value, const array … in http_response_xsendfile2() argument
485 buffer * const b = r->tmp_buf; in http_response_xsendfile2()
486 const int status = r->http_status; in http_response_xsendfile2()
489 if (light_btst(r->resp_htags, HTTP_HEADER_CONTENT_LENGTH)) { in http_response_xsendfile2()
490 http_header_response_unset(r, HTTP_HEADER_CONTENT_LENGTH, in http_response_xsendfile2()
505 log_error(r->conf.errh, __FILE__, __LINE__, in http_response_xsendfile2()
507 r->http_status = 502; in http_response_xsendfile2()
517 log_error(r->conf.errh, __FILE__, __LINE__, in http_response_xsendfile2()
519 r->http_status = 502; in http_response_xsendfile2()
523 if (r->conf.force_lowercase_filenames) { in http_response_xsendfile2()
527 r->http_status = 502; in http_response_xsendfile2()
531 const buffer * const xval = !r->conf.force_lowercase_filenames in http_response_xsendfile2()
535 log_error(r->conf.errh, __FILE__, __LINE__, in http_response_xsendfile2()
538 r->http_status = 403; in http_response_xsendfile2()
543 sce = stat_cache_get_entry_open(b, r->conf.follow_symlink); in http_response_xsendfile2()
545 log_error(r->conf.errh, __FILE__, __LINE__, in http_response_xsendfile2()
548 r->http_status = 404; in http_response_xsendfile2()
551 log_error(r->conf.errh, __FILE__, __LINE__, in http_response_xsendfile2()
553 r->http_status = 502; in http_response_xsendfile2()
578 log_error(r->conf.errh, __FILE__, __LINE__, in http_response_xsendfile2()
580 r->http_status = 502; in http_response_xsendfile2()
590 r->http_status = 502; in http_response_xsendfile2()
596 r->http_status = 502; in http_response_xsendfile2()
600 http_chunk_append_file_ref_range(r, sce, begin_range, range_len); in http_response_xsendfile2()
606 if (r->http_status >= 400 && status < 300) { in http_response_xsendfile2()
607 r->handler_module = NULL; in http_response_xsendfile2()
609 r->http_status = status; in http_response_xsendfile2()
614 void http_response_backend_error (request_st * const r) { in http_response_backend_error() argument
615 if (r->resp_body_started) { in http_response_backend_error()
618 r->handler_module = NULL; /*(avoid sending final chunked block)*/ in http_response_backend_error()
619 r->keep_alive = 0; in http_response_backend_error()
620 r->resp_body_finished = 1; in http_response_backend_error()
624 void http_response_backend_done (request_st * const r) { in http_response_backend_done() argument
628 switch (r->state) { in http_response_backend_done()
631 if (!r->resp_body_started) { in http_response_backend_done()
633 if (r->http_status < 500 && r->http_status != 400) in http_response_backend_done()
634 r->http_status = 500; in http_response_backend_done()
635 r->handler_module = NULL; in http_response_backend_done()
640 if (!r->resp_body_finished) { in http_response_backend_done()
641 if (r->http_version == HTTP_VERSION_1_1) in http_response_backend_done()
642 http_chunk_close(r); in http_response_backend_done()
662 else if (__builtin_expect( (r->http_version == HTTP_VERSION_1_0), 0) in http_response_backend_done()
663 && r->gw_dechunk && !r->gw_dechunk->done in http_response_backend_done()
664 && !(r->conf.stream_response_body in http_response_backend_done()
667 r->keep_alive = 0; /* disable keep-alive, send bogus length */ in http_response_backend_done()
668 http_header_response_set(r, HTTP_HEADER_CONTENT_LENGTH, in http_response_backend_done()
671 http_header_response_unset(r, HTTP_HEADER_ETAG, in http_response_backend_done()
673 http_header_response_unset(r, HTTP_HEADER_LAST_MODIFIED, in http_response_backend_done()
675 http_header_response_unset(r, HTTP_HEADER_CACHE_CONTROL, in http_response_backend_done()
677 http_header_response_unset(r, HTTP_HEADER_EXPIRES, in http_response_backend_done()
681 r->resp_body_finished = 1; in http_response_backend_done()
689 void http_response_upgrade_read_body_unknown(request_st * const r) { in http_response_upgrade_read_body_unknown() argument
691 if (!(r->conf.stream_request_body & FDEVENT_STREAM_REQUEST)) in http_response_upgrade_read_body_unknown()
692 r->conf.stream_request_body |= in http_response_upgrade_read_body_unknown()
694 if (!(r->conf.stream_response_body & FDEVENT_STREAM_RESPONSE)) in http_response_upgrade_read_body_unknown()
695 r->conf.stream_response_body |= in http_response_upgrade_read_body_unknown()
697 r->conf.stream_request_body |= FDEVENT_STREAM_REQUEST_POLLIN; in http_response_upgrade_read_body_unknown()
698 r->reqbody_length = -2; in http_response_upgrade_read_body_unknown()
699 r->resp_body_scratchpad = -1; in http_response_upgrade_read_body_unknown()
700 r->keep_alive = 0; in http_response_upgrade_read_body_unknown()
705 static int http_response_append_buffer_simple_accum(const request_st * const r, const off_t len) { in http_response_append_buffer_simple_accum() argument
708 len < 32768 && r->write_queue.last && r->write_queue.last->file.is_temp; in http_response_append_buffer_simple_accum()
712 static int http_response_append_buffer(request_st * const r, buffer * const mem, const int simple_a… in http_response_append_buffer() argument
716 if (r->resp_decode_chunked) in http_response_append_buffer()
717 return http_chunk_decode_append_buffer(r, mem); in http_response_append_buffer()
719 if (r->resp_body_scratchpad > 0) { in http_response_append_buffer()
721 r->resp_body_scratchpad -= len; in http_response_append_buffer()
722 if (r->resp_body_scratchpad > 0) { in http_response_append_buffer()
724 && http_response_append_buffer_simple_accum(r, len)) { in http_response_append_buffer()
725 r->resp_body_scratchpad += len; in http_response_append_buffer()
730 r->resp_body_finished = 1; in http_response_append_buffer()
731 if (__builtin_expect( (r->resp_body_scratchpad < 0), 0)) { in http_response_append_buffer()
733 len += r->resp_body_scratchpad; in http_response_append_buffer()
734 r->resp_body_scratchpad = 0; in http_response_append_buffer()
739 else if (0 == r->resp_body_scratchpad) { in http_response_append_buffer()
745 && http_response_append_buffer_simple_accum(r, buffer_clen(mem))) { in http_response_append_buffer()
748 return http_chunk_append_buffer(r, mem); in http_response_append_buffer()
753 static int http_response_append_splice(request_st * const r, http_response_opts * const opts, buffe… in http_response_append_splice() argument
756 if (r->resp_body_scratchpad >= toread in http_response_append_splice()
759 && r->write_queue.last && r->write_queue.last->file.is_temp))) { in http_response_append_splice()
763 int rc = http_response_append_buffer(r, b, 0); /*(0 to flush)*/ in http_response_append_splice()
771 &r->write_queue, fd, toread, r->conf.errh) in http_response_append_splice()
773 &r->write_queue, fd, toread, r->conf.errh); in http_response_append_splice()
775 if (0 == (r->resp_body_scratchpad -= n)) in http_response_append_splice()
776 r->resp_body_finished = 1; in http_response_append_splice()
788 static int http_response_append_mem(request_st * const r, const char * const mem, size_t len) { in http_response_append_mem() argument
789 if (r->resp_decode_chunked) in http_response_append_mem()
790 return http_chunk_decode_append_mem(r, mem, len); in http_response_append_mem()
792 if (r->resp_body_scratchpad > 0) { in http_response_append_mem()
793 r->resp_body_scratchpad -= (off_t)len; in http_response_append_mem()
794 if (r->resp_body_scratchpad <= 0) { in http_response_append_mem()
795 r->resp_body_finished = 1; in http_response_append_mem()
796 if (__builtin_expect( (r->resp_body_scratchpad < 0), 0)) { in http_response_append_mem()
798 len = (size_t)(r->resp_body_scratchpad + (off_t)len); in http_response_append_mem()
799 r->resp_body_scratchpad = 0; in http_response_append_mem()
803 else if (0 == r->resp_body_scratchpad) { in http_response_append_mem()
807 return http_chunk_append_mem(r, mem, len); in http_response_append_mem()
811 int http_response_transfer_cqlen(request_st * const r, chunkqueue * const cq, size_t len) { in http_response_transfer_cqlen() argument
816 if (__builtin_expect( (!r->resp_decode_chunked), 1)) { in http_response_transfer_cqlen()
818 if (r->resp_body_scratchpad >= 0) { in http_response_transfer_cqlen()
819 r->resp_body_scratchpad -= (off_t)len; in http_response_transfer_cqlen()
820 if (__builtin_expect( (r->resp_body_scratchpad < 0), 0)) { in http_response_transfer_cqlen()
822 len = (size_t)(r->resp_body_scratchpad + (off_t)len); in http_response_transfer_cqlen()
823 r->resp_body_scratchpad = 0; in http_response_transfer_cqlen()
826 int rc = http_chunk_transfer_cqlen(r, cq, len); in http_response_transfer_cqlen()
842 if (0 != http_chunk_decode_append_mem(r, c->mem->ptr+c->offset, wr)) in http_response_transfer_cqlen()
851 static int http_response_process_headers(request_st * const restrict r, http_response_opts * const … in http_response_process_headers() argument
867 r->http_status = status; in http_response_process_headers()
873 if (0 == r->http_status) { in http_response_process_headers()
874 log_error(r->conf.errh, __FILE__, __LINE__, in http_response_process_headers()
876 r->http_status = 502; /* Bad Gateway */ in http_response_process_headers()
877 r->handler_module = NULL; in http_response_process_headers()
883 r->http_status = 502; /* Bad Gateway */ in http_response_process_headers()
884 r->handler_module = NULL; in http_response_process_headers()
907 if (opts->authorizer && (0 == r->http_status || 200 == r->http_status)){ in http_response_process_headers()
915 r->http_status = status; in http_response_process_headers()
919 r->http_status = 502; /* Bad Gateway */ in http_response_process_headers()
925 http_header_env_append(r, k + 9, klen - 9, value, end - value); in http_response_process_headers()
939 r->http_status = status; in http_response_process_headers()
943 r->http_status = 502; in http_response_process_headers()
944 r->handler_module = NULL; in http_response_process_headers()
954 if (r->http_version >= HTTP_VERSION_2 && !r->h2_connect_ext) in http_response_process_headers()
962 r->keep_alive = 0; in http_response_process_headers()
963 if (r->http_version >= HTTP_VERSION_2) continue; in http_response_process_headers()
977 if (!r->resp_decode_chunked in http_response_process_headers()
978 && !light_btst(r->resp_htags, HTTP_HEADER_CONTENT_LENGTH)) { in http_response_process_headers()
983 r->resp_body_scratchpad = in http_response_process_headers()
989 r->resp_body_scratchpad = -1; in http_response_process_headers()
1000 if (light_btst(r->resp_htags, HTTP_HEADER_CONTENT_LENGTH)) { in http_response_process_headers()
1003 r->resp_body_scratchpad = -1; in http_response_process_headers()
1004 http_header_response_unset(r, HTTP_HEADER_CONTENT_LENGTH, in http_response_process_headers()
1008 r->resp_decode_chunked = 1; in http_response_process_headers()
1009 r->gw_dechunk = ck_calloc(1, sizeof(response_dechunk)); in http_response_process_headers()
1028 http_header_response_insert(r, id, k, klen, value, end - value); in http_response_process_headers()
1033 if (0 == r->http_status && light_btst(r->resp_htags, HTTP_HEADER_LOCATION)){ in http_response_process_headers()
1034 r->http_status = 302; in http_response_process_headers()
1055 http_response_send_1xx (request_st * const r) in http_response_send_1xx() argument
1058 if (r->http_version >= HTTP_VERSION_2) in http_response_send_1xx()
1060 else if (r->http_version == HTTP_VERSION_1_1) in http_response_send_1xx()
1063 if (http_response_send_1xx_fn && !http_response_send_1xx_fn(r, r->con)) in http_response_send_1xx()
1066 http_response_header_clear(r); in http_response_send_1xx()
1074 http_response_check_1xx (request_st * const r, buffer * const restrict b, uint32_t hlen, uint32_t d… in http_response_check_1xx() argument
1077 if (0 == r->http_status || 101 == r->http_status) in http_response_check_1xx()
1089 return http_response_send_1xx(r); in http_response_check_1xx()
1095 handler_t http_response_parse_headers(request_st * const r, http_response_opts * const opts, buffer… in http_response_parse_headers() argument
1128 log_error(r->conf.errh, __FILE__, __LINE__, in http_response_parse_headers()
1129 "response headers too large for %s", r->uri.path.ptr); in http_response_parse_headers()
1130 r->http_status = 502; /* Bad Gateway */ in http_response_parse_headers()
1131 r->handler_module = NULL; in http_response_parse_headers()
1146 if (0 != http_chunk_append_buffer(r, b)) { in http_response_parse_headers()
1149 r->http_status = 200; /* OK */ in http_response_parse_headers()
1150 r->resp_body_started = 1; in http_response_parse_headers()
1155 r->http_status = 502; /* Bad Gateway */ in http_response_parse_headers()
1156 r->handler_module = NULL; in http_response_parse_headers()
1169 if (0 != http_response_process_headers(r, opts, b->ptr, hoff, is_nph)) in http_response_parse_headers()
1172 } while (r->http_status < 200 in http_response_parse_headers()
1173 && http_response_check_1xx(r, b, bstart - b->ptr, blen)); in http_response_parse_headers()
1175 r->resp_body_started = 1; in http_response_parse_headers()
1178 && (r->http_status == 0 || r->http_status == 200)) { in http_response_parse_headers()
1182 if (NULL == r->handler_module) { in http_response_parse_headers()
1186 if (opts->local_redir && r->http_status >= 300 && r->http_status < 400 in http_response_parse_headers()
1191 handler_t rc = http_cgi_local_redir(r); in http_response_parse_headers()
1199 && NULL != (vb = http_header_response_get(r, HTTP_HEADER_OTHER, in http_response_parse_headers()
1201 http_response_xsendfile2(r, vb, opts->xsendfile_docroot); in http_response_parse_headers()
1204 if (NULL == r->handler_module) in http_response_parse_headers()
1205 r->resp_body_started = 0; in http_response_parse_headers()
1207 } else if (NULL != (vb = http_header_response_get(r, HTTP_HEADER_OTHER, in http_response_parse_headers()
1210 && NULL != (vb = http_header_response_get(r, HTTP_HEADER_OTHER, in http_response_parse_headers()
1212 http_response_xsendfile(r, vb, opts->xsendfile_docroot); in http_response_parse_headers()
1215 if (NULL == r->handler_module) in http_response_parse_headers()
1216 r->resp_body_started = 0; in http_response_parse_headers()
1225 int rc = http_response_append_mem(r, bstart, blen); in http_response_parse_headers()
1231 return (opts->headers) ? opts->headers(r, opts) : HANDLER_GO_ON; in http_response_parse_headers()
1235 handler_t http_response_read(request_st * const r, http_response_opts * const opts, buffer * const … in http_response_read() argument
1249 int rc = http_response_append_splice(r, opts, b, fd, toread); in http_response_read()
1271 if (toread > 8192 && !r->resp_body_started) toread = 8192; in http_response_read()
1280 if (!(r->conf.stream_response_body in http_response_read()
1293 if (r->conf.stream_response_body & FDEVENT_STREAM_RESPONSE_BUFMIN) { in http_response_read()
1294 off_t cqlen = chunkqueue_length(&r->write_queue); in http_response_read()
1296 if (!r->con->is_writable) { in http_response_read()
1302 fdevent_fdnode_event_clr(r->con->srv->ev, fdn, FDEVENT_IN); in http_response_read()
1341 log_perror(r->conf.errh, __FILE__, __LINE__, in http_response_read()
1342 "read() %d %d", r->con->fd, fd); in http_response_read()
1354 handler_t rc = opts->parse(r, opts, b, (size_t)n); in http_response_read()
1361 int rc = http_response_append_buffer(r, b, 0); /*(0 to flush)*/ in http_response_read()
1374 } else if (0 == r->resp_body_started) { in http_response_read()
1376 handler_t rc = http_response_parse_headers(r, opts, b); in http_response_read()
1379 if (r->resp_body_started) { in http_response_read()
1384 if (0 == r->resp_body_scratchpad) in http_response_read()
1385 r->resp_body_finished = 1; in http_response_read()
1392 else if (!r->resp_decode_chunked /* && NULL == opts->parse */ in http_response_read()
1393 && !(r->conf.stream_response_body in http_response_read()
1404 && (!(r->conf.stream_response_body in http_response_read()
1406 || !r->con->is_writable); in http_response_read()
1407 int rc = http_response_append_buffer(r, b, simple_accum); in http_response_read()
1417 if (r->conf.stream_response_body & FDEVENT_STREAM_RESPONSE_BUFMIN) { in http_response_read()
1418 if (chunkqueue_length(&r->write_queue) > 65536 - 4096) { in http_response_read()
1424 if (!r->con->is_writable) in http_response_read()
1425 fdevent_fdnode_event_clr(r->con->srv->ev, fdn, FDEVENT_IN); in http_response_read()
1429 } while (!r->resp_body_started); /*(loop to read large response headers)*/ in http_response_read()
1436 return (!r->resp_body_finished ? HANDLER_GO_ON : HANDLER_FINISHED); in http_response_read()