Skip to content

Commit

Permalink
Better response header parsing. (Gets rid of one of the 'TODO's).
Browse files Browse the repository at this point in the history
git-svn-id: svn://cherokee-project.com/cherokee/trunk@6872 5dc97367-97f1-0310-9951-d761b3857238
  • Loading branch information
alobbs committed Oct 1, 2011
1 parent 1294b06 commit 9af3264
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions cherokee/header.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ parse_response_first_line (cherokee_header_t *hdr, cherokee_buffer_t *buf, char
char tmp[4];
char *end;
size_t len;
int n;
char *line = buf->buf;
char *begin = buf->buf;

Expand Down Expand Up @@ -244,9 +245,6 @@ parse_response_first_line (cherokee_header_t *hdr, cherokee_buffer_t *buf, char
* HTTP/1.0 403 Forbidden
*/
if (unlikely(! cmp_str(begin, "HTTP/1."))) {
/* TODO: improve parser
* (if ! "HTTP/" then leave default http_bad_request).
*/
*error_code = http_version_not_supported;
return ret_error;
}
Expand All @@ -267,10 +265,24 @@ parse_response_first_line (cherokee_header_t *hdr, cherokee_buffer_t *buf, char
break;
}

/* Skip whites - there must at least one
*/
if (unlikely (CHEROKEE_CHAR_IS_WHITE (begin[8]))) {
return ret_error;
}

n = 9;
while (CHEROKEE_CHAR_IS_WHITE (begin[n])) {
n++;
}

/* Read the response code
* TODO: skip spaces properly (usually there is only one blank).
*/
memcpy (tmp, begin+9, 3);
if (unlikely ((begin + n + 3 > end))) {
return ret_error;
}

memcpy (tmp, begin+n, 3);
tmp[3] = '\0';

ret = cherokee_atoi (tmp, (int *)&hdr->response);
Expand Down

0 comments on commit 9af3264

Please sign in to comment.