Browse Source

Some fixes for HEAD and 206 Partial Content handling

personal/stbuehler/wip
Stefan Bühler 13 years ago
parent
commit
90447c6cec
  1. 5
      src/main/response.c
  2. 20
      src/modules/mod_deflate.c

5
src/main/response.c

@ -33,8 +33,6 @@ gboolean li_response_send_headers(liConnection *con) {
if (0 == con->out->length && con->mainvr->backend == NULL
&& vr->response.http_status >= 400 && vr->response.http_status < 600) {
/*li_chunkqueue_append_mem(con->out, CONST_STR_LEN("Custom error\r\n"));*/
li_response_send_error_page(con);
}
@ -45,7 +43,8 @@ gboolean li_response_send_headers(liConnection *con) {
/* They never have a content-body/length */
li_chunkqueue_reset(con->out);
con->out->is_closed = TRUE;
} else if (con->out->is_closed) {
} else if (con->out->is_closed && (vr->request.http_method != LI_HTTP_METHOD_HEAD || con->out->length > 0)) {
/* do not send content-length: 0 if backend already skipped content generation for HEAD */
g_string_printf(con->wrk->tmp_str, "%"L_GOFFSET_FORMAT, con->out->length);
li_http_header_overwrite(vr->response.headers, CONST_STR_LEN("Content-Length"), GSTR_LEN(con->wrk->tmp_str));
} else if (con->keep_alive && vr->request.http_version == LI_HTTP_VERSION_1_1) {

20
src/modules/mod_deflate.c

@ -5,7 +5,7 @@
* compress content on the fly
*
* Does not compress:
* - response status: 100, 101, 204, 205, 304
* - response status: 100, 101, 204, 205, 206, 304
* - already compressed content
* - if more than one etag response header is sent
* - if no common encoding is found
@ -468,6 +468,13 @@ static liHandlerResult deflate_filter_bzip2(liVRequest *vr, liFilter *f) {
}
#endif /* HAVE_BZIP */
static liHandlerResult deflate_filter_null(liVRequest *vr, liFilter *f) {
UNUSED(vr);
li_chunkqueue_skip_all(f->in);
f->out->is_closed = f->in->is_closed = TRUE;
return LI_HANDLER_GO_ON;
}
/**********************************************************************************/
/* returns TRUE if handled with 304, FALSE otherwise */
@ -512,6 +519,7 @@ static liHandlerResult deflate_handle(liVRequest *vr, gpointer param, gpointer *
case 101:
case 204:
case 205:
case 206:
case 304:
/* disable compression as we have no response entity */
return LI_HANDLER_GO_ON;
@ -527,6 +535,9 @@ static liHandlerResult deflate_handle(liVRequest *vr, gpointer param, gpointer *
return LI_HANDLER_GO_ON;
}
/* announce that we have looked for accept-encoding */
li_http_header_append(vr->response.headers, CONST_STR_LEN("Vary"), CONST_STR_LEN("Accept-Encoding"));
hh_encoding_entry = li_http_header_find_first(vr->request.headers, CONST_STR_LEN("accept-encoding"));
while (hh_encoding_entry) {
hh_encoding = (liHttpHeader*) hh_encoding_entry->data;
@ -611,8 +622,13 @@ static liHandlerResult deflate_handle(liVRequest *vr, gpointer param, gpointer *
return LI_HANDLER_GO_ON;
}
if (is_head_request) {
/* kill content so response.c doesn't send wrong content-length */
liFilter *f = li_vrequest_add_filter_out(vr, deflate_filter_null, NULL, NULL);
f->out->is_closed = f->in->is_closed = TRUE;
}
li_http_header_insert(vr->response.headers, CONST_STR_LEN("Content-Encoding"), encoding_names[i], strlen(encoding_names[i]));
li_http_header_append(vr->response.headers, CONST_STR_LEN("Vary"), CONST_STR_LEN("Accept-Encoding"));
li_http_header_remove(vr->response.headers, CONST_STR_LEN("content-length"));
return LI_HANDLER_GO_ON;

Loading…
Cancel
Save