mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-14 06:49:35 -04:00
fix cases where there is no content or transfer encoding was specified
from Dug Song svn:r291
This commit is contained in:
parent
7fe5edf50c
commit
ec0679199f
21
http.c
21
http.c
@ -302,21 +302,26 @@ evhttp_make_header_response(struct evhttp_connection *evcon,
|
|||||||
req->response_code_line);
|
req->response_code_line);
|
||||||
evbuffer_add(evcon->output_buffer, line, strlen(line));
|
evbuffer_add(evcon->output_buffer, line, strlen(line));
|
||||||
|
|
||||||
/* Potentially add headers */
|
/* Potentially add headers for unidentified content. */
|
||||||
if (evhttp_find_header(req->output_headers, "Content-Type") == NULL) {
|
if (EVBUFFER_LENGTH(req->output_buffer) &&
|
||||||
|
evhttp_find_header(req->output_headers, "Content-Type") == NULL) {
|
||||||
evhttp_add_header(req->output_headers,
|
evhttp_add_header(req->output_headers,
|
||||||
"Content-Type", "text/html; charset=ISO-8859-1");
|
"Content-Type", "text/html; charset=ISO-8859-1");
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* we need to add the content length if the user did not give it,
|
* we need to add the content length if the user did
|
||||||
* this is required for persistent connections to work.
|
* not give it, this is required for persistent
|
||||||
|
* connections to work.
|
||||||
*/
|
*/
|
||||||
if (evhttp_find_header(req->output_headers, "Content-Length") == NULL){
|
if (evhttp_find_header(req->output_headers,
|
||||||
|
"Transfer-Encoding") == NULL &&
|
||||||
|
evhttp_find_header(req->output_headers,
|
||||||
|
"Content-Length") == NULL) {
|
||||||
static char len[12];
|
static char len[12];
|
||||||
snprintf(len, sizeof(len), "%ld",
|
snprintf(len, sizeof(len), "%ld",
|
||||||
(long)EVBUFFER_LENGTH(req->output_buffer));
|
(long)EVBUFFER_LENGTH(req->output_buffer));
|
||||||
evhttp_add_header(req->output_headers, "Content-Length", len);
|
evhttp_add_header(req->output_headers,
|
||||||
|
"Content-Length", len);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if the request asked for a close, we send a close, too */
|
/* if the request asked for a close, we send a close, too */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user