diff --git a/http-internal.h b/http-internal.h index fe14a230..d25753bb 100644 --- a/http-internal.h +++ b/http-internal.h @@ -151,6 +151,7 @@ struct evhttp { size_t default_max_headers_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 * callbacks. */ diff --git a/http.c b/http.c index 4452d31b..5eb91dfe 100644 --- a/http.c +++ b/http.c @@ -552,9 +552,11 @@ evhttp_make_header_response(struct evhttp_connection *evcon, /* Potentially add headers for unidentified content. */ if (evhttp_response_needs_body(req)) { 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, - "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); evhttp_set_max_headers_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_REQ_GET | 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; } +void +evhttp_set_default_content_type(struct evhttp *http, + const char *content_type) { + http->default_content_type = content_type; +} + void evhttp_set_allowed_methods(struct evhttp* http, ev_uint16_t methods) { diff --git a/include/event2/http.h b/include/event2/http.h index 0db75ed4..cf44941d 100644 --- a/include/event2/http.h +++ b/include/event2/http.h @@ -206,6 +206,17 @@ void evhttp_set_max_headers_size(struct evhttp* http, ev_ssize_t max_headers_siz /** XXX Document. */ 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 server, and passed to user callbacks.