I guess this should work. It only sends the range header if the response is 206. The patch is attached
hamza On 14 July 2013 19:38, Sonny Karlsson <[email protected]> wrote: > On Sun, Jul 14, 2013 at 06:34:06PM +0200, Hamza Zia wrote: > > From: hamza zia <[email protected]> > > > > Some plugins may want to support HTTP range requests so it is parsed and > > filled in the request headers before calling the plugin. > > This is a good idea, but these changes are not enough to support this. > > If a plugin that isn't aware of the range headers serves a request with > range headers, the response headers will be invalid. > Monkey will add "Content-Range:" in mk_header_send(). > > I think you could make some changes so that these headers are only added > on 206 responses. > > > --- > > src/mk_http.c | 21 +++++++++++---------- > > 1 file changed, 11 insertions(+), 10 deletions(-) > > > > diff --git a/src/mk_http.c b/src/mk_http.c > > index 0f8a976..700cbda 100644 > > --- a/src/mk_http.c > > +++ b/src/mk_http.c > > @@ -135,6 +135,9 @@ static int mk_http_range_set(struct session_request > *sr, long file_size) > > > > lseek(sr->fd_file, sr->bytes_offset, SEEK_SET); > > } > > + > > + sh->content_length = sr->bytes_to_send; > > + > > return 0; > > } > > > > @@ -168,7 +171,6 @@ static int mk_http_range_parse(struct > session_request *sr) > > return -1; > > } > > > > - sh->content_length = sh->ranges[1]; > > return 0; > > } > > > > @@ -186,16 +188,15 @@ static int mk_http_range_parse(struct > session_request *sr) > > return -1; > > } > > > > - sh->content_length = abs(sh->ranges[1] - sh->ranges[0]) + 1; > > return 0; > > } > > /* =yyy- */ > > if ((eq_pos + 1 != sep_pos) && (len == sep_pos + 1)) { > > buffer = mk_string_copy_substr(sr->range.data, eq_pos + 1, len); > > sr->headers.ranges[0] = (unsigned long) atol(buffer); > > + sr->headers.ranges[1] = -1; > > mk_mem_free(buffer); > > > > - sh->content_length = (sh->content_length - sh->ranges[0]); > > return 0; > > } > > > > @@ -372,6 +373,11 @@ int mk_http_init(struct client_session *cs, struct > session_request *sr) > > return mk_request_error(MK_CLIENT_FORBIDDEN, cs, sr); > > } > > > > + /* Parse HTTP Ranges */ > > + sr->headers.ranges[0] = sr->headers.ranges[1] = -1; > > + if (sr->range.data != NULL && mk_http_range_parse(sr) < 0) { > > + return mk_request_error(MK_CLIENT_BAD_REQUEST, cs, sr); > > + } > > > > if (mk_file_get_info(sr->real_path.data, &sr->file_info) != 0) { > > /* if the resource requested doesn't exists, let's > > @@ -546,13 +552,8 @@ int mk_http_init(struct client_session *cs, struct > session_request *sr) > > if (sr->method == HTTP_METHOD_GET || sr->method == > HTTP_METHOD_HEAD) { > > sr->headers.content_type = mime->type; > > > > - /* HTTP Ranges */ > > - if (sr->range.data != NULL && config->resume == MK_TRUE) { > > - if (mk_http_range_parse(sr) < 0) { > > - sr->headers.ranges[0] = -1; > > - sr->headers.ranges[1] = -1; > > - return mk_request_error(MK_CLIENT_BAD_REQUEST, cs, sr); > > - } > > + /* Use parsed HTTP Range if available */ > > + if (config->resume == MK_TRUE) { > > if (sr->headers.ranges[0] >= 0 || sr->headers.ranges[1] >= > 0) { > > mk_header_set_http_status(sr, MK_HTTP_PARTIAL); > > } > > -- > > 1.8.1.2 > > > > _______________________________________________ > > Monkey mailing list > > [email protected] > > http://lists.monkey-project.com/listinfo/monkey > > -- > Sonny Karlsson > _______________________________________________ > Monkey mailing list > [email protected] > http://lists.monkey-project.com/listinfo/monkey >
0001-Parse-HTTP-Ranges-before-calling-stage30-plugins.patch
Description: Binary data
_______________________________________________ Monkey mailing list [email protected] http://lists.monkey-project.com/listinfo/monkey
