Lines Matching refs:req
211 struct evhttp_request *req);
213 struct evhttp_request *req);
379 struct evhttp_request *req)
383 evhttp_remove_header(req->output_headers, "Proxy-Connection");
386 method = evhttp_method(req->type);
388 method, req->uri, req->major, req->minor);
391 if (req->type == EVHTTP_REQ_POST &&
392 evhttp_find_header(req->output_headers, "Content-Length") == NULL){
395 (long)EVBUFFER_LENGTH(req->output_buffer));
396 evhttp_add_header(req->output_headers, "Content-Length", size);
462 struct evhttp_request *req)
464 int is_keepalive = evhttp_is_connection_keepalive(req->input_headers);
466 req->major, req->minor, req->response_code,
467 req->response_code_line);
469 if (req->major == 1) {
470 if (req->minor == 1)
471 evhttp_maybe_add_date_header(req->output_headers);
477 if (req->minor == 0 && is_keepalive)
478 evhttp_add_header(req->output_headers,
481 if (req->minor == 1 || is_keepalive) {
488 req->output_headers,
489 (long)EVBUFFER_LENGTH(req->output_buffer));
494 if (EVBUFFER_LENGTH(req->output_buffer)) {
495 if (evhttp_find_header(req->output_headers,
497 evhttp_add_header(req->output_headers,
503 if (evhttp_is_connection_close(req->flags, req->input_headers)) {
504 evhttp_remove_header(req->output_headers, "Connection");
505 if (!(req->flags & EVHTTP_PROXY_REQUEST))
506 evhttp_add_header(req->output_headers, "Connection", "close");
507 evhttp_remove_header(req->output_headers, "Proxy-Connection");
512 evhttp_make_header(struct evhttp_connection *evcon, struct evhttp_request *req)
520 if (req->kind == EVHTTP_REQUEST) {
521 evhttp_make_header_request(evcon, req);
523 evhttp_make_header_response(evcon, req);
526 TAILQ_FOREACH(header, req->output_headers, next) {
532 if (EVBUFFER_LENGTH(req->output_buffer) > 0) {
537 evbuffer_add_buffer(evcon->output_buffer, req->output_buffer);
599 evhttp_connection_incoming_fail(struct evhttp_request *req,
615 if (req->uri) {
616 free(req->uri);
617 req->uri = NULL;
624 (*req->cb)(req, req->cb_arg);
634 struct evhttp_request* req = TAILQ_FIRST(&evcon->requests);
637 assert(req != NULL);
648 req, error) == -1)
654 cb = req->cb;
655 cb_arg = req->cb_arg;
657 TAILQ_REMOVE(&evcon->requests, req, next);
658 evhttp_request_free(req);
719 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests);
725 TAILQ_REMOVE(&evcon->requests, req, next);
726 req->evcon = NULL;
731 evhttp_is_connection_close(req->flags, req->input_headers)||
732 evhttp_is_connection_close(req->flags, req->output_headers);
763 (*req->cb)(req, req->cb_arg);
767 evhttp_request_free(req);
784 evhttp_handle_chunked_read(struct evhttp_request *req, struct evbuffer *buf)
789 if (req->ntoread < 0) {
811 req->ntoread = ntoread;
812 if (req->ntoread == 0) {
820 if (len < req->ntoread)
824 evbuffer_add(req->input_buffer,
825 EVBUFFER_DATA(buf), (size_t)req->ntoread);
826 evbuffer_drain(buf, (size_t)req->ntoread);
827 req->ntoread = -1;
828 if (req->chunk_cb != NULL) {
829 (*req->chunk_cb)(req, req->cb_arg);
830 evbuffer_drain(req->input_buffer,
831 EVBUFFER_LENGTH(req->input_buffer));
839 evhttp_read_trailer(struct evhttp_connection *evcon, struct evhttp_request *req)
843 switch (evhttp_parse_headers(req, buf)) {
860 evhttp_read_body(struct evhttp_connection *evcon, struct evhttp_request *req)
864 if (req->chunked) {
865 switch (evhttp_handle_chunked_read(req, buf)) {
869 evhttp_read_trailer(evcon, req);
878 evhttp_request_free(req);
884 } else if (req->ntoread < 0) {
886 evbuffer_add_buffer(req->input_buffer, buf);
887 } else if (EVBUFFER_LENGTH(buf) >= req->ntoread) {
889 evbuffer_add(req->input_buffer, EVBUFFER_DATA(buf),
890 (size_t)req->ntoread);
891 evbuffer_drain(buf, (size_t)req->ntoread);
892 req->ntoread = 0;
913 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests);
942 evhttp_read_firstline(evcon, req);
945 evhttp_read_header(evcon, req);
948 evhttp_read_body(evcon, req);
951 evhttp_read_trailer(evcon, req);
967 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests);
968 assert(req != NULL);
973 req->kind = EVHTTP_RESPONSE;
985 struct evhttp_request *req;
994 while ((req = TAILQ_FIRST(&evcon->requests)) != NULL) {
995 TAILQ_REMOVE(&evcon->requests, req, next);
996 evhttp_request_free(req);
1050 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests);
1053 if (req == NULL)
1065 evhttp_make_header(evcon, req);
1212 evhttp_parse_response_line(struct evhttp_request *req, char *line)
1227 req->major = 1;
1228 req->minor = 0;
1230 req->major = 1;
1231 req->minor = 1;
1238 req->response_code = atoi(number);
1239 if (!evhttp_valid_response_code(req->response_code)) {
1245 if ((req->response_code_line = strdup(readable)) == NULL)
1254 evhttp_parse_request_line(struct evhttp_request *req, char *line)
1273 req->type = EVHTTP_REQ_GET;
1275 req->type = EVHTTP_REQ_POST;
1277 req->type = EVHTTP_REQ_HEAD;
1280 __func__, method, req, req->remote_host));
1285 req->major = 1;
1286 req->minor = 0;
1288 req->major = 1;
1289 req->minor = 1;
1292 __func__, version, req, req->remote_host));
1296 if ((req->uri = strdup(uri)) == NULL) {
1302 if (strlen(req->uri) > 0 && req->uri[0] != '/')
1303 req->flags |= EVHTTP_PROXY_REQUEST;
1435 evhttp_parse_firstline(struct evhttp_request *req, struct evbuffer *buffer)
1444 switch (req->kind) {
1446 if (evhttp_parse_request_line(req, line) == -1)
1450 if (evhttp_parse_response_line(req, line) == -1)
1485 evhttp_parse_headers(struct evhttp_request *req, struct evbuffer* buffer)
1490 struct evkeyvalq* headers = req->input_headers;
1531 evhttp_get_body_length(struct evhttp_request *req)
1533 struct evkeyvalq *headers = req->input_headers;
1541 req->ntoread = -1;
1550 req->ntoread = -1;
1559 req->ntoread = ntoread;
1563 __func__, req->ntoread,
1564 EVBUFFER_LENGTH(req->evcon->input_buffer)));
1570 evhttp_get_body(struct evhttp_connection *evcon, struct evhttp_request *req)
1575 if (req->kind == EVHTTP_REQUEST && req->type != EVHTTP_REQ_POST) {
1580 xfer_enc = evhttp_find_header(req->input_headers, "Transfer-Encoding");
1582 req->chunked = 1;
1583 req->ntoread = -1;
1585 if (evhttp_get_body_length(req) == -1) {
1591 evhttp_read_body(evcon, req);
1596 struct evhttp_request *req)
1600 res = evhttp_parse_firstline(req, evcon->input_buffer);
1615 evhttp_read_header(evcon, req);
1619 evhttp_read_header(struct evhttp_connection *evcon, struct evhttp_request *req)
1624 res = evhttp_parse_headers(req, evcon->input_buffer);
1638 switch (req->kind) {
1642 evhttp_get_body(evcon, req);
1646 if (req->response_code == HTTP_NOCONTENT ||
1647 req->response_code == HTTP_NOTMODIFIED ||
1648 (req->response_code >= 100 && req->response_code < 200)) {
1650 __func__, req->response_code));
1654 __func__, req->remote_host, fd));
1655 evhttp_get_body(evcon, req);
1800 struct evhttp_request *req,
1804 req->kind = EVHTTP_REQUEST;
1805 req->type = type;
1806 if (req->uri != NULL)
1807 free(req->uri);
1808 if ((req->uri = strdup(uri)) == NULL)
1812 if (!req->major && !req->minor) {
1813 req->major = 1;
1814 req->minor = 1;
1817 assert(req->evcon == NULL);
1818 req->evcon = evcon;
1819 assert(!(req->flags & EVHTTP_REQ_OWN_CONNECTION));
1821 TAILQ_INSERT_TAIL(&evcon->requests, req, next);
1832 if (TAILQ_FIRST(&evcon->requests) == req)
1860 struct evhttp_request *req = TAILQ_FIRST(&evcon->requests);
1861 TAILQ_REMOVE(&evcon->requests, req, next);
1867 (req->minor == 0 &&
1868 !evhttp_is_connection_keepalive(req->input_headers))||
1869 evhttp_is_connection_close(req->flags, req->input_headers) ||
1870 evhttp_is_connection_close(req->flags, req->output_headers);
1872 assert(req->flags & EVHTTP_REQ_OWN_CONNECTION);
1873 evhttp_request_free(req);
1890 evhttp_send_error(struct evhttp_request *req, int error, const char *reason)
1902 evhttp_add_header(req->output_headers, "Connection", "close");
1904 evhttp_response_code(req, error, reason);
1908 evhttp_send_page(req, buf);
1917 evhttp_send(struct evhttp_request *req, struct evbuffer *databuf)
1919 struct evhttp_connection *evcon = req->evcon;
1921 assert(TAILQ_FIRST(&evcon->requests) == req);
1925 evbuffer_add_buffer(req->output_buffer, databuf);
1928 evhttp_make_header(evcon, req);
1934 evhttp_send_reply(struct evhttp_request *req, int code, const char *reason,
1937 evhttp_response_code(req, code, reason);
1939 evhttp_send(req, databuf);
1943 evhttp_send_reply_start(struct evhttp_request *req, int code,
1946 evhttp_response_code(req, code, reason);
1947 if (req->major == 1 && req->minor == 1) {
1949 evhttp_add_header(req->output_headers, "Transfer-Encoding",
1951 req->chunked = 1;
1953 evhttp_make_header(req->evcon, req);
1954 evhttp_write_buffer(req->evcon, NULL, NULL);
1958 evhttp_send_reply_chunk(struct evhttp_request *req, struct evbuffer *databuf)
1960 if (req->chunked) {
1961 evbuffer_add_printf(req->evcon->output_buffer, "%x\r\n",
1964 evbuffer_add_buffer(req->evcon->output_buffer, databuf);
1965 if (req->chunked) {
1966 evbuffer_add(req->evcon->output_buffer, "\r\n", 2);
1968 evhttp_write_buffer(req->evcon, NULL, NULL);
1972 evhttp_send_reply_end(struct evhttp_request *req)
1974 struct evhttp_connection *evcon = req->evcon;
1976 if (req->chunked) {
1977 evbuffer_add(req->evcon->output_buffer, "0\r\n\r\n", 5);
1978 evhttp_write_buffer(req->evcon, evhttp_send_done, NULL);
1979 req->chunked = 0;
1991 evhttp_response_code(struct evhttp_request *req, int code, const char *reason)
1993 req->kind = EVHTTP_RESPONSE;
1994 req->response_code = code;
1995 if (req->response_code_line != NULL)
1996 free(req->response_code_line);
1997 req->response_code_line = strdup(reason);
2001 evhttp_send_page(struct evhttp_request *req, struct evbuffer *databuf)
2003 if (!req->major || !req->minor) {
2004 req->major = 1;
2005 req->minor = 1;
2008 if (req->kind != EVHTTP_RESPONSE)
2009 evhttp_response_code(req, 200, "OK");
2011 evhttp_clear_headers(req->output_headers);
2012 evhttp_add_header(req->output_headers, "Content-Type", "text/html");
2013 evhttp_add_header(req->output_headers, "Connection", "close");
2015 evhttp_send(req, databuf);
2161 evhttp_dispatch_callback(struct httpcbq *callbacks, struct evhttp_request *req)
2167 char *p = strchr(req->uri, '?');
2169 offset = (size_t)(p - req->uri);
2174 res = strcmp(cb->what, req->uri) == 0;
2176 res = ((strncmp(cb->what, req->uri, offset) == 0) &&
2188 evhttp_handle_request(struct evhttp_request *req, void *arg)
2193 if (req->uri == NULL) {
2194 evhttp_send_error(req, HTTP_BADREQUEST, "Bad Request");
2198 if ((cb = evhttp_dispatch_callback(&http->callbacks, req)) != NULL) {
2199 (*cb->cb)(req, cb->cbarg);
2205 (*http->gencb)(req, http->gencbarg);
2216 char *escaped_html = evhttp_htmlescape(req->uri);
2219 evhttp_response_code(req, HTTP_NOTFOUND, "Not Found");
2225 evhttp_send_page(req, buf);
2439 struct evhttp_request *req = NULL;
2442 if ((req = calloc(1, sizeof(struct evhttp_request))) == NULL) {
2447 req->kind = EVHTTP_RESPONSE;
2448 req->input_headers = calloc(1, sizeof(struct evkeyvalq));
2449 if (req->input_headers == NULL) {
2453 TAILQ_INIT(req->input_headers);
2455 req->output_headers = calloc(1, sizeof(struct evkeyvalq));
2456 if (req->output_headers == NULL) {
2460 TAILQ_INIT(req->output_headers);
2462 if ((req->input_buffer = evbuffer_new()) == NULL) {
2467 if ((req->output_buffer = evbuffer_new()) == NULL) {
2472 req->cb = cb;
2473 req->cb_arg = arg;
2475 return (req);
2478 if (req != NULL)
2479 evhttp_request_free(req);
2484 evhttp_request_free(struct evhttp_request *req)
2486 if (req->remote_host != NULL)
2487 free(req->remote_host);
2488 if (req->uri != NULL)
2489 free(req->uri);
2490 if (req->response_code_line != NULL)
2491 free(req->response_code_line);
2493 evhttp_clear_headers(req->input_headers);
2494 free(req->input_headers);
2496 evhttp_clear_headers(req->output_headers);
2497 free(req->output_headers);
2499 if (req->input_buffer != NULL)
2500 evbuffer_free(req->input_buffer);
2502 if (req->output_buffer != NULL)
2503 evbuffer_free(req->output_buffer);
2505 free(req);
2509 evhttp_request_set_chunked_cb(struct evhttp_request *req,
2512 req->chunk_cb = cb;
2520 evhttp_request_uri(struct evhttp_request *req) {
2521 if (req->uri == NULL)
2522 event_debug(("%s: request %p has no uri\n", __func__, req));
2523 return (req->uri);
2571 struct evhttp_request *req;
2572 if ((req = evhttp_request_new(evhttp_handle_request, http)) == NULL)
2575 req->evcon = evcon; /* the request ends up owning the connection */
2576 req->flags |= EVHTTP_REQ_OWN_CONNECTION;
2578 TAILQ_INSERT_TAIL(&evcon->requests, req, next);
2580 req->kind = EVHTTP_REQUEST;
2582 if ((req->remote_host = strdup(evcon->address)) == NULL)
2584 req->remote_port = evcon->port;