• Home
  • Raw
  • Download

Lines Matching refs:req

159 #define REQ_VERSION_BEFORE(req, major_v, minor_v)			\  argument
160 ((req)->major < (major_v) || \
161 ((req)->major == (major_v) && (req)->minor < (minor_v)))
163 #define REQ_VERSION_ATLEAST(req, major_v, minor_v) \ argument
164 ((req)->major > (major_v) || \
165 ((req)->major == (major_v) && (req)->minor >= (minor_v)))
184 struct evhttp_request *req);
186 struct evhttp_request *req);
348 evhttp_response_needs_body(struct evhttp_request *req) in evhttp_response_needs_body() argument
350 return (req->response_code != HTTP_NOCONTENT && in evhttp_response_needs_body()
351 req->response_code != HTTP_NOTMODIFIED && in evhttp_response_needs_body()
352 (req->response_code < 100 || req->response_code >= 200) && in evhttp_response_needs_body()
353 req->type != EVHTTP_REQ_HEAD); in evhttp_response_needs_body()
390 struct evhttp_request *req) in evhttp_send_continue() argument
395 req->major, req->minor); in evhttp_send_continue()
430 struct evhttp_request *req) in evhttp_make_header_request() argument
434 evhttp_remove_header(req->output_headers, "Proxy-Connection"); in evhttp_make_header_request()
437 if (!(method = evhttp_method(req->type))) { in evhttp_make_header_request()
443 method, req->uri, req->major, req->minor); in evhttp_make_header_request()
446 if ((req->type == EVHTTP_REQ_POST || req->type == EVHTTP_REQ_PUT) && in evhttp_make_header_request()
447 evhttp_find_header(req->output_headers, "Content-Length") == NULL){ in evhttp_make_header_request()
450 EV_SIZE_ARG(evbuffer_get_length(req->output_buffer))); in evhttp_make_header_request()
451 evhttp_add_header(req->output_headers, "Content-Length", size); in evhttp_make_header_request()
471 evhttp_is_request_connection_close(struct evhttp_request *req) in evhttp_is_request_connection_close() argument
474 evhttp_is_connection_close(req->flags, req->input_headers) || in evhttp_is_request_connection_close()
475 evhttp_is_connection_close(req->flags, req->output_headers); in evhttp_is_request_connection_close()
520 struct evhttp_request *req) in evhttp_make_header_response() argument
522 int is_keepalive = evhttp_is_connection_keepalive(req->input_headers); in evhttp_make_header_response()
525 req->major, req->minor, req->response_code, in evhttp_make_header_response()
526 req->response_code_line); in evhttp_make_header_response()
528 if (req->major == 1) { in evhttp_make_header_response()
529 if (req->minor >= 1) in evhttp_make_header_response()
530 evhttp_maybe_add_date_header(req->output_headers); in evhttp_make_header_response()
536 if (req->minor == 0 && is_keepalive) in evhttp_make_header_response()
537 evhttp_add_header(req->output_headers, in evhttp_make_header_response()
540 if ((req->minor >= 1 || is_keepalive) && in evhttp_make_header_response()
541 evhttp_response_needs_body(req)) { in evhttp_make_header_response()
548 req->output_headers, in evhttp_make_header_response()
549 evbuffer_get_length(req->output_buffer)); in evhttp_make_header_response()
554 if (evhttp_response_needs_body(req)) { in evhttp_make_header_response()
555 if (evhttp_find_header(req->output_headers, in evhttp_make_header_response()
558 evhttp_add_header(req->output_headers, in evhttp_make_header_response()
565 if (evhttp_is_connection_close(req->flags, req->input_headers)) { in evhttp_make_header_response()
566 evhttp_remove_header(req->output_headers, "Connection"); in evhttp_make_header_response()
567 if (!(req->flags & EVHTTP_PROXY_REQUEST)) in evhttp_make_header_response()
568 evhttp_add_header(req->output_headers, "Connection", "close"); in evhttp_make_header_response()
569 evhttp_remove_header(req->output_headers, "Proxy-Connection"); in evhttp_make_header_response()
574 static enum expect evhttp_have_expect(struct evhttp_request *req, int input) in evhttp_have_expect() argument
577 struct evkeyvalq *h = input ? req->input_headers : req->output_headers; in evhttp_have_expect()
579 if (!(req->kind == EVHTTP_REQUEST) || !REQ_VERSION_ATLEAST(req, 1, 1)) in evhttp_have_expect()
594 evhttp_make_header(struct evhttp_connection *evcon, struct evhttp_request *req) in evhttp_make_header() argument
603 if (req->kind == EVHTTP_REQUEST) { in evhttp_make_header()
604 evhttp_make_header_request(evcon, req); in evhttp_make_header()
606 evhttp_make_header_response(evcon, req); in evhttp_make_header()
609 TAILQ_FOREACH(header, req->output_headers, next) { in evhttp_make_header()
615 if (evhttp_have_expect(req, 0) != CONTINUE && in evhttp_make_header()
616 evbuffer_get_length(req->output_buffer)) { in evhttp_make_header()
621 evbuffer_add_buffer(output, req->output_buffer); in evhttp_make_header()
645 evhttp_connection_incoming_fail(struct evhttp_request *req, in evhttp_connection_incoming_fail() argument
650 req->response_code = HTTP_ENTITYTOOLARGE; in evhttp_connection_incoming_fail()
653 req->response_code = HTTP_BADREQUEST; in evhttp_connection_incoming_fail()
667 if (!req->userdone) { in evhttp_connection_incoming_fail()
669 TAILQ_REMOVE(&req->evcon->requests, req, next); in evhttp_connection_incoming_fail()
673 req->evcon = NULL; in evhttp_connection_incoming_fail()
682 if (req->uri) { in evhttp_connection_incoming_fail()
683 mm_free(req->uri); in evhttp_connection_incoming_fail()
684 req->uri = NULL; in evhttp_connection_incoming_fail()
686 if (req->uri_elems) { in evhttp_connection_incoming_fail()
687 evhttp_uri_free(req->uri_elems); in evhttp_connection_incoming_fail()
688 req->uri_elems = NULL; in evhttp_connection_incoming_fail()
695 (*req->cb)(req, req->cb_arg); in evhttp_connection_incoming_fail()
704 evhttp_request_free_auto(struct evhttp_request *req) in evhttp_request_free_auto() argument
706 if (!(req->flags & EVHTTP_USER_OWNED)) in evhttp_request_free_auto()
707 evhttp_request_free(req); in evhttp_request_free_auto()
711 evhttp_request_free_(struct evhttp_connection *evcon, struct evhttp_request *req) in evhttp_request_free_() argument
713 TAILQ_REMOVE(&evcon->requests, req, next); in evhttp_request_free_()
714 evhttp_request_free_auto(req); in evhttp_request_free_()
726 struct evhttp_request* req = TAILQ_FIRST(&evcon->requests); in evhttp_connection_fail_() local
731 EVUTIL_ASSERT(req != NULL); in evhttp_connection_fail_()
744 if (evhttp_connection_incoming_fail(req, error) == -1) in evhttp_connection_fail_()
749 error_cb = req->error_cb; in evhttp_connection_fail_()
750 error_cb_arg = req->cb_arg; in evhttp_connection_fail_()
754 cb = req->cb; in evhttp_connection_fail_()
755 cb_arg = req->cb_arg; in evhttp_connection_fail_()
765 evhttp_request_free_(evcon, req); in evhttp_connection_fail_()
809 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); in evhttp_connection_done() local
815 int need_close = evhttp_is_request_connection_close(req); in evhttp_connection_done()
816 TAILQ_REMOVE(&evcon->requests, req, next); in evhttp_connection_done()
817 req->evcon = NULL; in evhttp_connection_done()
856 (*req->cb)(req, req->cb_arg); in evhttp_connection_done()
860 evhttp_request_free_auto(req); in evhttp_connection_done()
889 evhttp_handle_chunked_read(struct evhttp_request *req, struct evbuffer *buf) in evhttp_handle_chunked_read() argument
891 if (req == NULL || buf == NULL) { in evhttp_handle_chunked_read()
908 if (req->ntoread < 0) { in evhttp_handle_chunked_read()
932 if ((ev_uint64_t)ntoread > EV_SIZE_MAX - req->body_size) { in evhttp_handle_chunked_read()
936 if (req->body_size + (size_t)ntoread > req->evcon->max_body_size) { in evhttp_handle_chunked_read()
942 req->body_size += (size_t)ntoread; in evhttp_handle_chunked_read()
943 req->ntoread = ntoread; in evhttp_handle_chunked_read()
944 if (req->ntoread == 0) { in evhttp_handle_chunked_read()
953 if (req->ntoread > EV_SSIZE_MAX) { in evhttp_handle_chunked_read()
958 if (req->ntoread > 0 && buflen < (ev_uint64_t)req->ntoread) in evhttp_handle_chunked_read()
962 evbuffer_remove_buffer(buf, req->input_buffer, (size_t)req->ntoread); in evhttp_handle_chunked_read()
963 req->ntoread = -1; in evhttp_handle_chunked_read()
964 if (req->chunk_cb != NULL) { in evhttp_handle_chunked_read()
965 req->flags |= EVHTTP_REQ_DEFER_FREE; in evhttp_handle_chunked_read()
966 (*req->chunk_cb)(req, req->cb_arg); in evhttp_handle_chunked_read()
967 evbuffer_drain(req->input_buffer, in evhttp_handle_chunked_read()
968 evbuffer_get_length(req->input_buffer)); in evhttp_handle_chunked_read()
969 req->flags &= ~EVHTTP_REQ_DEFER_FREE; in evhttp_handle_chunked_read()
970 if ((req->flags & EVHTTP_REQ_NEEDS_FREE) != 0) { in evhttp_handle_chunked_read()
980 evhttp_read_trailer(struct evhttp_connection *evcon, struct evhttp_request *req) in evhttp_read_trailer() argument
984 switch (evhttp_parse_headers_(req, buf)) { in evhttp_read_trailer()
1002 struct evhttp_request *req) in evhttp_lingering_close() argument
1007 if (n > (size_t) req->ntoread) in evhttp_lingering_close()
1008 n = (size_t) req->ntoread; in evhttp_lingering_close()
1009 req->ntoread -= n; in evhttp_lingering_close()
1010 req->body_size += n; in evhttp_lingering_close()
1013 EV_I64_ARG(req->ntoread))); in evhttp_lingering_close()
1016 if (!req->ntoread) in evhttp_lingering_close()
1021 struct evhttp_request *req) in evhttp_lingering_fail() argument
1024 evhttp_lingering_close(evcon, req); in evhttp_lingering_fail()
1030 evhttp_read_body(struct evhttp_connection *evcon, struct evhttp_request *req) in evhttp_read_body() argument
1034 if (req->chunked) { in evhttp_read_body()
1035 switch (evhttp_handle_chunked_read(req, buf)) { in evhttp_read_body()
1039 evhttp_read_trailer(evcon, req); in evhttp_read_body()
1049 evhttp_request_free_auto(req); in evhttp_read_body()
1055 } else if (req->ntoread < 0) { in evhttp_read_body()
1057 if ((size_t)(req->body_size + evbuffer_get_length(buf)) < req->body_size) { in evhttp_read_body()
1062 req->body_size += evbuffer_get_length(buf); in evhttp_read_body()
1063 evbuffer_add_buffer(req->input_buffer, buf); in evhttp_read_body()
1064 } else if (req->chunk_cb != NULL || evbuffer_get_length(buf) >= (size_t)req->ntoread) { in evhttp_read_body()
1070 if (n > (size_t) req->ntoread) in evhttp_read_body()
1071 n = (size_t) req->ntoread; in evhttp_read_body()
1072 req->ntoread -= n; in evhttp_read_body()
1073 req->body_size += n; in evhttp_read_body()
1074 evbuffer_remove_buffer(buf, req->input_buffer, n); in evhttp_read_body()
1077 if (req->body_size > req->evcon->max_body_size || in evhttp_read_body()
1078 (!req->chunked && req->ntoread >= 0 && in evhttp_read_body()
1079 (size_t)req->ntoread > req->evcon->max_body_size)) { in evhttp_read_body()
1083 evhttp_lingering_fail(evcon, req); in evhttp_read_body()
1087 if (evbuffer_get_length(req->input_buffer) > 0 && req->chunk_cb != NULL) { in evhttp_read_body()
1088 req->flags |= EVHTTP_REQ_DEFER_FREE; in evhttp_read_body()
1089 (*req->chunk_cb)(req, req->cb_arg); in evhttp_read_body()
1090 req->flags &= ~EVHTTP_REQ_DEFER_FREE; in evhttp_read_body()
1091 evbuffer_drain(req->input_buffer, in evhttp_read_body()
1092 evbuffer_get_length(req->input_buffer)); in evhttp_read_body()
1093 if ((req->flags & EVHTTP_REQ_NEEDS_FREE) != 0) { in evhttp_read_body()
1094 evhttp_request_free_auto(req); in evhttp_read_body()
1099 if (!req->ntoread) { in evhttp_read_body()
1118 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); in evhttp_read_cb() local
1126 evhttp_read_firstline(evcon, req); in evhttp_read_cb()
1131 evhttp_read_header(evcon, req); in evhttp_read_cb()
1136 evhttp_read_body(evcon, req); in evhttp_read_cb()
1141 evhttp_read_trailer(evcon, req); in evhttp_read_cb()
1180 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); in evhttp_write_connectioncb() local
1182 EVUTIL_ASSERT(req != NULL); in evhttp_write_connectioncb()
1192 req->kind = EVHTTP_RESPONSE; in evhttp_write_connectioncb()
1204 struct evhttp_request *req; in evhttp_connection_free() local
1217 while ((req = TAILQ_FIRST(&evcon->requests)) != NULL) { in evhttp_connection_free()
1218 evhttp_request_free_(evcon, req); in evhttp_connection_free()
1284 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); in evhttp_request_dispatch() local
1287 if (req == NULL) in evhttp_request_dispatch()
1299 evhttp_make_header(evcon, req); in evhttp_request_dispatch()
1432 struct evhttp_request *req) in evhttp_connection_read_on_write_error() argument
1443 req->kind = EVHTTP_RESPONSE; in evhttp_connection_read_on_write_error()
1458 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); in evhttp_error_cb() local
1476 if (!req->chunked && req->ntoread < 0 in evhttp_error_cb()
1525 evhttp_connection_read_on_write_error(evcon, req); in evhttp_error_cb()
1632 evhttp_parse_http_version(const char *version, struct evhttp_request *req) in evhttp_parse_http_version() argument
1639 __func__, version, req, req->remote_host)); in evhttp_parse_http_version()
1642 req->major = major; in evhttp_parse_http_version()
1643 req->minor = minor; in evhttp_parse_http_version()
1650 evhttp_parse_response_line(struct evhttp_request *req, char *line) in evhttp_parse_response_line() argument
1663 if (evhttp_parse_http_version(protocol, req) < 0) in evhttp_parse_response_line()
1666 req->response_code = atoi(number); in evhttp_parse_response_line()
1667 if (!evhttp_valid_response_code(req->response_code)) { in evhttp_parse_response_line()
1673 if (req->response_code_line != NULL) in evhttp_parse_response_line()
1674 mm_free(req->response_code_line); in evhttp_parse_response_line()
1675 if ((req->response_code_line = mm_strdup(readable)) == NULL) { in evhttp_parse_response_line()
1686 evhttp_parse_request_line(struct evhttp_request *req, char *line) in evhttp_parse_request_line() argument
1817 __func__, method, req, req->remote_host)); in evhttp_parse_request_line()
1822 req->type = type; in evhttp_parse_request_line()
1824 if (evhttp_parse_http_version(version, req) < 0) in evhttp_parse_request_line()
1827 if ((req->uri = mm_strdup(uri)) == NULL) { in evhttp_parse_request_line()
1832 if ((req->uri_elems = evhttp_uri_parse_with_flags(req->uri, in evhttp_parse_request_line()
1840 scheme = evhttp_uri_get_scheme(req->uri_elems); in evhttp_parse_request_line()
1841 hostname = evhttp_uri_get_host(req->uri_elems); in evhttp_parse_request_line()
1845 !evhttp_find_vhost(req->evcon->http_server, NULL, hostname)) in evhttp_parse_request_line()
1846 req->flags |= EVHTTP_PROXY_REQUEST; in evhttp_parse_request_line()
1978 evhttp_parse_firstline_(struct evhttp_request *req, struct evbuffer *buffer) in evhttp_parse_firstline_() argument
1987 if (req->evcon != NULL && in evhttp_parse_firstline_()
1988 evbuffer_get_length(buffer) > req->evcon->max_headers_size) in evhttp_parse_firstline_()
1994 if (req->evcon != NULL && in evhttp_parse_firstline_()
1995 line_length > req->evcon->max_headers_size) { in evhttp_parse_firstline_()
2000 req->headers_size = line_length; in evhttp_parse_firstline_()
2002 switch (req->kind) { in evhttp_parse_firstline_()
2004 if (evhttp_parse_request_line(req, line) == -1) in evhttp_parse_firstline_()
2008 if (evhttp_parse_response_line(req, line) == -1) in evhttp_parse_firstline_()
2050 evhttp_parse_headers_(struct evhttp_request *req, struct evbuffer* buffer) in evhttp_parse_headers_() argument
2056 struct evkeyvalq* headers = req->input_headers; in evhttp_parse_headers_()
2062 req->headers_size += line_length; in evhttp_parse_headers_()
2064 if (req->evcon != NULL && in evhttp_parse_headers_()
2065 req->headers_size > req->evcon->max_headers_size) { in evhttp_parse_headers_()
2100 if (req->evcon != NULL && in evhttp_parse_headers_()
2101 req->headers_size + evbuffer_get_length(buffer) > req->evcon->max_headers_size) in evhttp_parse_headers_()
2113 evhttp_get_body_length(struct evhttp_request *req) in evhttp_get_body_length() argument
2115 struct evkeyvalq *headers = req->input_headers; in evhttp_get_body_length()
2123 req->ntoread = -1; in evhttp_get_body_length()
2132 req->ntoread = -1; in evhttp_get_body_length()
2141 req->ntoread = ntoread; in evhttp_get_body_length()
2145 __func__, EV_I64_ARG(req->ntoread), in evhttp_get_body_length()
2146 EV_SIZE_ARG(evbuffer_get_length(bufferevent_get_input(req->evcon->bufev))))); in evhttp_get_body_length()
2174 evhttp_get_body(struct evhttp_connection *evcon, struct evhttp_request *req) in evhttp_get_body() argument
2179 if (req->kind == EVHTTP_REQUEST && in evhttp_get_body()
2180 !evhttp_method_may_have_body(req->type)) { in evhttp_get_body()
2185 xfer_enc = evhttp_find_header(req->input_headers, "Transfer-Encoding"); in evhttp_get_body()
2187 req->chunked = 1; in evhttp_get_body()
2188 req->ntoread = -1; in evhttp_get_body()
2190 if (evhttp_get_body_length(req) == -1) { in evhttp_get_body()
2194 if (req->kind == EVHTTP_REQUEST && req->ntoread < 1) { in evhttp_get_body()
2203 switch (evhttp_have_expect(req, 1)) { in evhttp_get_body()
2211 if (req->ntoread > 0) { in evhttp_get_body()
2213 if ((req->evcon->max_body_size <= EV_INT64_MAX) && in evhttp_get_body()
2214 (ev_uint64_t)req->ntoread > req->evcon->max_body_size) { in evhttp_get_body()
2215 evhttp_lingering_fail(evcon, req); in evhttp_get_body()
2220 evhttp_send_continue(evcon, req); in evhttp_get_body()
2223 evhttp_send_error(req, HTTP_EXPECTATIONFAILED, NULL); in evhttp_get_body()
2228 evhttp_read_body(evcon, req); in evhttp_get_body()
2234 struct evhttp_request *req) in evhttp_read_firstline() argument
2238 res = evhttp_parse_firstline_(req, bufferevent_get_input(evcon->bufev)); in evhttp_read_firstline()
2251 evhttp_read_header(evcon, req); in evhttp_read_firstline()
2256 struct evhttp_request *req) in evhttp_read_header() argument
2261 res = evhttp_parse_headers_(req, bufferevent_get_input(evcon->bufev)); in evhttp_read_header()
2274 if (req->header_cb != NULL) { in evhttp_read_header()
2275 if ((*req->header_cb)(req, req->cb_arg) < 0) { in evhttp_read_header()
2282 switch (req->kind) { in evhttp_read_header()
2286 evhttp_get_body(evcon, req); in evhttp_read_header()
2292 if (req->response_code == 100) { in evhttp_read_header()
2294 evbuffer_add_buffer(output, req->output_buffer); in evhttp_read_header()
2298 if (!evhttp_response_needs_body(req)) { in evhttp_read_header()
2300 __func__, req->response_code)); in evhttp_read_header()
2305 __func__, req->remote_host, EV_SOCK_ARG(fd))); in evhttp_read_header()
2306 evhttp_get_body(evcon, req); in evhttp_read_header()
2605 struct evhttp_request *req, in evhttp_make_request() argument
2609 req->kind = EVHTTP_REQUEST; in evhttp_make_request()
2610 req->type = type; in evhttp_make_request()
2611 if (req->uri != NULL) in evhttp_make_request()
2612 mm_free(req->uri); in evhttp_make_request()
2613 if ((req->uri = mm_strdup(uri)) == NULL) { in evhttp_make_request()
2615 evhttp_request_free_auto(req); in evhttp_make_request()
2620 if (!req->major && !req->minor) { in evhttp_make_request()
2621 req->major = 1; in evhttp_make_request()
2622 req->minor = 1; in evhttp_make_request()
2625 EVUTIL_ASSERT(req->evcon == NULL); in evhttp_make_request()
2626 req->evcon = evcon; in evhttp_make_request()
2627 EVUTIL_ASSERT(!(req->flags & EVHTTP_REQ_OWN_CONNECTION)); in evhttp_make_request()
2629 TAILQ_INSERT_TAIL(&evcon->requests, req, next); in evhttp_make_request()
2639 TAILQ_REMOVE(&evcon->requests, req, next); in evhttp_make_request()
2649 if (TAILQ_FIRST(&evcon->requests) == req) in evhttp_make_request()
2656 evhttp_cancel_request(struct evhttp_request *req) in evhttp_cancel_request() argument
2658 struct evhttp_connection *evcon = req->evcon; in evhttp_cancel_request()
2661 if (TAILQ_FIRST(&evcon->requests) == req) { in evhttp_cancel_request()
2674 TAILQ_REMOVE(&evcon->requests, req, next); in evhttp_cancel_request()
2678 evhttp_request_free_auto(req); in evhttp_cancel_request()
2722 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests); in evhttp_send_done() local
2723 TAILQ_REMOVE(&evcon->requests, req, next); in evhttp_send_done()
2725 if (req->on_complete_cb != NULL) { in evhttp_send_done()
2726 req->on_complete_cb(req, req->on_complete_cb_arg); in evhttp_send_done()
2730 (REQ_VERSION_BEFORE(req, 1, 1) && in evhttp_send_done()
2731 !evhttp_is_connection_keepalive(req->input_headers)) || in evhttp_send_done()
2732 evhttp_is_request_connection_close(req); in evhttp_send_done()
2734 EVUTIL_ASSERT(req->flags & EVHTTP_REQ_OWN_CONNECTION); in evhttp_send_done()
2735 evhttp_request_free(req); in evhttp_send_done()
2753 evhttp_send_error(struct evhttp_request *req, int error, const char *reason) in evhttp_send_error() argument
2765 evhttp_connection_free(req->evcon); in evhttp_send_error()
2772 evhttp_response_code_(req, error, reason); in evhttp_send_error()
2776 evhttp_send_page_(req, buf); in evhttp_send_error()
2785 evhttp_send(struct evhttp_request *req, struct evbuffer *databuf) in evhttp_send() argument
2787 struct evhttp_connection *evcon = req->evcon; in evhttp_send()
2790 evhttp_request_free(req); in evhttp_send()
2794 EVUTIL_ASSERT(TAILQ_FIRST(&evcon->requests) == req); in evhttp_send()
2797 req->userdone = 1; in evhttp_send()
2801 evbuffer_add_buffer(req->output_buffer, databuf); in evhttp_send()
2804 evhttp_make_header(evcon, req); in evhttp_send()
2810 evhttp_send_reply(struct evhttp_request *req, int code, const char *reason, in evhttp_send_reply() argument
2813 evhttp_response_code_(req, code, reason); in evhttp_send_reply()
2815 evhttp_send(req, databuf); in evhttp_send_reply()
2819 evhttp_send_reply_start(struct evhttp_request *req, int code, in evhttp_send_reply_start() argument
2822 evhttp_response_code_(req, code, reason); in evhttp_send_reply_start()
2823 if (evhttp_find_header(req->output_headers, "Content-Length") == NULL && in evhttp_send_reply_start()
2824 REQ_VERSION_ATLEAST(req, 1, 1) && in evhttp_send_reply_start()
2825 evhttp_response_needs_body(req)) { in evhttp_send_reply_start()
2831 evhttp_add_header(req->output_headers, "Transfer-Encoding", in evhttp_send_reply_start()
2833 req->chunked = 1; in evhttp_send_reply_start()
2835 req->chunked = 0; in evhttp_send_reply_start()
2837 evhttp_make_header(req->evcon, req); in evhttp_send_reply_start()
2838 evhttp_write_buffer(req->evcon, NULL, NULL); in evhttp_send_reply_start()
2842 evhttp_send_reply_chunk_with_cb(struct evhttp_request *req, struct evbuffer *databuf, in evhttp_send_reply_chunk_with_cb() argument
2845 struct evhttp_connection *evcon = req->evcon; in evhttp_send_reply_chunk_with_cb()
2855 if (!evhttp_response_needs_body(req)) in evhttp_send_reply_chunk_with_cb()
2857 if (req->chunked) { in evhttp_send_reply_chunk_with_cb()
2862 if (req->chunked) { in evhttp_send_reply_chunk_with_cb()
2869 evhttp_send_reply_chunk(struct evhttp_request *req, struct evbuffer *databuf) in evhttp_send_reply_chunk() argument
2871 evhttp_send_reply_chunk_with_cb(req, databuf, NULL, NULL); in evhttp_send_reply_chunk()
2874 evhttp_send_reply_end(struct evhttp_request *req) in evhttp_send_reply_end() argument
2876 struct evhttp_connection *evcon = req->evcon; in evhttp_send_reply_end()
2880 evhttp_request_free(req); in evhttp_send_reply_end()
2887 req->userdone = 1; in evhttp_send_reply_end()
2889 if (req->chunked) { in evhttp_send_reply_end()
2891 evhttp_write_buffer(req->evcon, evhttp_send_done, NULL); in evhttp_send_reply_end()
2892 req->chunked = 0; in evhttp_send_reply_end()
2994 evhttp_response_code_(struct evhttp_request *req, int code, const char *reason) in evhttp_response_code_() argument
2996 req->kind = EVHTTP_RESPONSE; in evhttp_response_code_()
2997 req->response_code = code; in evhttp_response_code_()
2998 if (req->response_code_line != NULL) in evhttp_response_code_()
2999 mm_free(req->response_code_line); in evhttp_response_code_()
3002 req->response_code_line = mm_strdup(reason); in evhttp_response_code_()
3003 if (req->response_code_line == NULL) { in evhttp_response_code_()
3010 evhttp_send_page_(struct evhttp_request *req, struct evbuffer *databuf) in evhttp_send_page_() argument
3012 if (!req->major || !req->minor) { in evhttp_send_page_()
3013 req->major = 1; in evhttp_send_page_()
3014 req->minor = 1; in evhttp_send_page_()
3017 if (req->kind != EVHTTP_RESPONSE) in evhttp_send_page_()
3018 evhttp_response_code_(req, 200, "OK"); in evhttp_send_page_()
3020 evhttp_clear_headers(req->output_headers); in evhttp_send_page_()
3021 evhttp_add_header(req->output_headers, "Content-Type", "text/html"); in evhttp_send_page_()
3022 evhttp_add_header(req->output_headers, "Connection", "close"); in evhttp_send_page_()
3024 evhttp_send(req, databuf); in evhttp_send_page_()
3280 evhttp_dispatch_callback(struct httpcbq *callbacks, struct evhttp_request *req) in evhttp_dispatch_callback() argument
3288 path = evhttp_uri_get_path(req->uri_elems); in evhttp_dispatch_callback()
3410 evhttp_handle_request(struct evhttp_request *req, void *arg) in evhttp_handle_request() argument
3417 req->userdone = 0; in evhttp_handle_request()
3419 if (req->type == 0 || req->uri == NULL) { in evhttp_handle_request()
3420 evhttp_send_error(req, req->response_code, NULL); in evhttp_handle_request()
3424 if ((http->allowed_methods & req->type) == 0) { in evhttp_handle_request()
3426 (unsigned)req->type, (unsigned)http->allowed_methods)); in evhttp_handle_request()
3427 evhttp_send_error(req, HTTP_NOTIMPLEMENTED, NULL); in evhttp_handle_request()
3432 hostname = evhttp_request_get_host(req); in evhttp_handle_request()
3437 if ((cb = evhttp_dispatch_callback(&http->callbacks, req)) != NULL) { in evhttp_handle_request()
3438 (*cb->cb)(req, cb->cbarg); in evhttp_handle_request()
3444 (*http->gencb)(req, http->gencbarg); in evhttp_handle_request()
3458 if ((escaped_html = evhttp_htmlescape(req->uri)) == NULL) { in evhttp_handle_request()
3459 evhttp_connection_free(req->evcon); in evhttp_handle_request()
3465 evhttp_connection_free(req->evcon); in evhttp_handle_request()
3469 evhttp_response_code_(req, HTTP_NOTFOUND, "Not Found"); in evhttp_handle_request()
3475 evhttp_send_page_(req, buf); in evhttp_handle_request()
3925 struct evhttp_request *req = NULL; in evhttp_request_new() local
3928 if ((req = mm_calloc(1, sizeof(struct evhttp_request))) == NULL) { in evhttp_request_new()
3933 req->headers_size = 0; in evhttp_request_new()
3934 req->body_size = 0; in evhttp_request_new()
3936 req->kind = EVHTTP_RESPONSE; in evhttp_request_new()
3937 req->input_headers = mm_calloc(1, sizeof(struct evkeyvalq)); in evhttp_request_new()
3938 if (req->input_headers == NULL) { in evhttp_request_new()
3942 TAILQ_INIT(req->input_headers); in evhttp_request_new()
3944 req->output_headers = mm_calloc(1, sizeof(struct evkeyvalq)); in evhttp_request_new()
3945 if (req->output_headers == NULL) { in evhttp_request_new()
3949 TAILQ_INIT(req->output_headers); in evhttp_request_new()
3951 if ((req->input_buffer = evbuffer_new()) == NULL) { in evhttp_request_new()
3956 if ((req->output_buffer = evbuffer_new()) == NULL) { in evhttp_request_new()
3961 req->cb = cb; in evhttp_request_new()
3962 req->cb_arg = arg; in evhttp_request_new()
3964 return (req); in evhttp_request_new()
3967 if (req != NULL) in evhttp_request_new()
3968 evhttp_request_free(req); in evhttp_request_new()
3973 evhttp_request_free(struct evhttp_request *req) in evhttp_request_free() argument
3975 if ((req->flags & EVHTTP_REQ_DEFER_FREE) != 0) { in evhttp_request_free()
3976 req->flags |= EVHTTP_REQ_NEEDS_FREE; in evhttp_request_free()
3980 if (req->remote_host != NULL) in evhttp_request_free()
3981 mm_free(req->remote_host); in evhttp_request_free()
3982 if (req->uri != NULL) in evhttp_request_free()
3983 mm_free(req->uri); in evhttp_request_free()
3984 if (req->uri_elems != NULL) in evhttp_request_free()
3985 evhttp_uri_free(req->uri_elems); in evhttp_request_free()
3986 if (req->response_code_line != NULL) in evhttp_request_free()
3987 mm_free(req->response_code_line); in evhttp_request_free()
3988 if (req->host_cache != NULL) in evhttp_request_free()
3989 mm_free(req->host_cache); in evhttp_request_free()
3991 evhttp_clear_headers(req->input_headers); in evhttp_request_free()
3992 mm_free(req->input_headers); in evhttp_request_free()
3994 evhttp_clear_headers(req->output_headers); in evhttp_request_free()
3995 mm_free(req->output_headers); in evhttp_request_free()
3997 if (req->input_buffer != NULL) in evhttp_request_free()
3998 evbuffer_free(req->input_buffer); in evhttp_request_free()
4000 if (req->output_buffer != NULL) in evhttp_request_free()
4001 evbuffer_free(req->output_buffer); in evhttp_request_free()
4003 mm_free(req); in evhttp_request_free()
4007 evhttp_request_own(struct evhttp_request *req) in evhttp_request_own() argument
4009 req->flags |= EVHTTP_USER_OWNED; in evhttp_request_own()
4013 evhttp_request_is_owned(struct evhttp_request *req) in evhttp_request_is_owned() argument
4015 return (req->flags & EVHTTP_USER_OWNED) != 0; in evhttp_request_is_owned()
4019 evhttp_request_get_connection(struct evhttp_request *req) in evhttp_request_get_connection() argument
4021 return req->evcon; in evhttp_request_get_connection()
4031 evhttp_request_set_chunked_cb(struct evhttp_request *req, in evhttp_request_set_chunked_cb() argument
4034 req->chunk_cb = cb; in evhttp_request_set_chunked_cb()
4038 evhttp_request_set_header_cb(struct evhttp_request *req, in evhttp_request_set_header_cb() argument
4041 req->header_cb = cb; in evhttp_request_set_header_cb()
4045 evhttp_request_set_error_cb(struct evhttp_request *req, in evhttp_request_set_error_cb() argument
4048 req->error_cb = cb; in evhttp_request_set_error_cb()
4052 evhttp_request_set_on_complete_cb(struct evhttp_request *req, in evhttp_request_set_on_complete_cb() argument
4055 req->on_complete_cb = cb; in evhttp_request_set_on_complete_cb()
4056 req->on_complete_cb_arg = cb_arg; in evhttp_request_set_on_complete_cb()
4064 evhttp_request_get_uri(const struct evhttp_request *req) { in evhttp_request_get_uri() argument
4065 if (req->uri == NULL) in evhttp_request_get_uri()
4066 event_debug(("%s: request %p has no uri\n", __func__, req)); in evhttp_request_get_uri()
4067 return (req->uri); in evhttp_request_get_uri()
4071 evhttp_request_get_evhttp_uri(const struct evhttp_request *req) { in evhttp_request_get_evhttp_uri() argument
4072 if (req->uri_elems == NULL) in evhttp_request_get_evhttp_uri()
4074 __func__, req)); in evhttp_request_get_evhttp_uri()
4075 return (req->uri_elems); in evhttp_request_get_evhttp_uri()
4079 evhttp_request_get_host(struct evhttp_request *req) in evhttp_request_get_host() argument
4083 if (req->host_cache) in evhttp_request_get_host()
4084 return req->host_cache; in evhttp_request_get_host()
4086 if (req->uri_elems) in evhttp_request_get_host()
4087 host = evhttp_uri_get_host(req->uri_elems); in evhttp_request_get_host()
4088 if (!host && req->input_headers) { in evhttp_request_get_host()
4092 host = evhttp_find_header(req->input_headers, "Host"); in evhttp_request_get_host()
4101 req->host_cache = mm_malloc(len + 1); in evhttp_request_get_host()
4102 if (!req->host_cache) { in evhttp_request_get_host()
4106 memcpy(req->host_cache, host, len); in evhttp_request_get_host()
4107 req->host_cache[len] = '\0'; in evhttp_request_get_host()
4108 host = req->host_cache; in evhttp_request_get_host()
4117 evhttp_request_get_command(const struct evhttp_request *req) { in evhttp_request_get_command() argument
4118 return (req->type); in evhttp_request_get_command()
4122 evhttp_request_get_response_code(const struct evhttp_request *req) in evhttp_request_get_response_code() argument
4124 return req->response_code; in evhttp_request_get_response_code()
4128 evhttp_request_get_response_code_line(const struct evhttp_request *req) in evhttp_request_get_response_code_line() argument
4130 return req->response_code_line; in evhttp_request_get_response_code_line()
4134 struct evkeyvalq *evhttp_request_get_input_headers(struct evhttp_request *req) in evhttp_request_get_input_headers() argument
4136 return (req->input_headers); in evhttp_request_get_input_headers()
4140 struct evkeyvalq *evhttp_request_get_output_headers(struct evhttp_request *req) in evhttp_request_get_output_headers() argument
4142 return (req->output_headers); in evhttp_request_get_output_headers()
4146 struct evbuffer *evhttp_request_get_input_buffer(struct evhttp_request *req) in evhttp_request_get_input_buffer() argument
4148 return (req->input_buffer); in evhttp_request_get_input_buffer()
4152 struct evbuffer *evhttp_request_get_output_buffer(struct evhttp_request *req) in evhttp_request_get_output_buffer() argument
4154 return (req->output_buffer); in evhttp_request_get_output_buffer()
4214 struct evhttp_request *req; in evhttp_associate_new_request_with_connection() local
4215 if ((req = evhttp_request_new(evhttp_handle_request, http)) == NULL) in evhttp_associate_new_request_with_connection()
4218 if ((req->remote_host = mm_strdup(evcon->address)) == NULL) { in evhttp_associate_new_request_with_connection()
4220 evhttp_request_free(req); in evhttp_associate_new_request_with_connection()
4223 req->remote_port = evcon->port; in evhttp_associate_new_request_with_connection()
4225 req->evcon = evcon; /* the request ends up owning the connection */ in evhttp_associate_new_request_with_connection()
4226 req->flags |= EVHTTP_REQ_OWN_CONNECTION; in evhttp_associate_new_request_with_connection()
4233 req->userdone = 1; in evhttp_associate_new_request_with_connection()
4235 TAILQ_INSERT_TAIL(&evcon->requests, req, next); in evhttp_associate_new_request_with_connection()
4237 req->kind = EVHTTP_REQUEST; in evhttp_associate_new_request_with_connection()