Merge remote-tracking branch 'origin/pr/79'

This commit is contained in:
Nick Mathewson 2013-10-10 16:09:45 -04:00
commit 206124a23c
3 changed files with 23 additions and 2 deletions

View File

@ -151,6 +151,7 @@ struct evhttp {
size_t default_max_headers_size; size_t default_max_headers_size;
ev_uint64_t default_max_body_size; ev_uint64_t default_max_body_size;
const char *default_content_type;
/* Bitmask of all HTTP methods that we accept and pass to user /* Bitmask of all HTTP methods that we accept and pass to user
* callbacks. */ * callbacks. */

13
http.c
View File

@ -552,9 +552,11 @@ evhttp_make_header_response(struct evhttp_connection *evcon,
/* Potentially add headers for unidentified content. */ /* Potentially add headers for unidentified content. */
if (evhttp_response_needs_body(req)) { if (evhttp_response_needs_body(req)) {
if (evhttp_find_header(req->output_headers, if (evhttp_find_header(req->output_headers,
"Content-Type") == NULL) { "Content-Type") == NULL
&& evcon->http_server->default_content_type) {
evhttp_add_header(req->output_headers, evhttp_add_header(req->output_headers,
"Content-Type", "text/html; charset=ISO-8859-1"); "Content-Type",
evcon->http_server->default_content_type);
} }
} }
@ -3389,6 +3391,7 @@ evhttp_new_object(void)
evutil_timerclear(&http->timeout); evutil_timerclear(&http->timeout);
evhttp_set_max_headers_size(http, EV_SIZE_MAX); evhttp_set_max_headers_size(http, EV_SIZE_MAX);
evhttp_set_max_body_size(http, EV_SIZE_MAX); evhttp_set_max_body_size(http, EV_SIZE_MAX);
evhttp_set_default_content_type(http, "text/html; charset=ISO-8859-1");
evhttp_set_allowed_methods(http, evhttp_set_allowed_methods(http,
EVHTTP_REQ_GET | EVHTTP_REQ_GET |
EVHTTP_REQ_POST | EVHTTP_REQ_POST |
@ -3595,6 +3598,12 @@ evhttp_set_max_body_size(struct evhttp* http, ev_ssize_t max_body_size)
http->default_max_body_size = max_body_size; http->default_max_body_size = max_body_size;
} }
void
evhttp_set_default_content_type(struct evhttp *http,
const char *content_type) {
http->default_content_type = content_type;
}
void void
evhttp_set_allowed_methods(struct evhttp* http, ev_uint16_t methods) evhttp_set_allowed_methods(struct evhttp* http, ev_uint16_t methods)
{ {

View File

@ -206,6 +206,17 @@ void evhttp_set_max_headers_size(struct evhttp* http, ev_ssize_t max_headers_siz
/** XXX Document. */ /** XXX Document. */
void evhttp_set_max_body_size(struct evhttp* http, ev_ssize_t max_body_size); void evhttp_set_max_body_size(struct evhttp* http, ev_ssize_t max_body_size);
/**
Set the value to use for the Content-Type header when none was provided. If
the content type string is NULL, the Content-Type header will not be
automatically added.
@param http the http server on which to set the default content type
@param content_type the value for the Content-Type header
*/
void evhttp_set_default_content_type(struct evhttp *http,
const char *content_type);
/** /**
Sets the what HTTP methods are supported in requests accepted by this Sets the what HTTP methods are supported in requests accepted by this
server, and passed to user callbacks. server, and passed to user callbacks.