mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
allow \r or \n individually to separate HTTP headers instead of
the standard "\r\n"; from Charles Kerr. svn:r406
This commit is contained in:
parent
49e01ff789
commit
11a0a9e42f
@ -1 +1,2 @@
|
|||||||
Changes in current version:
|
Changes in current version:
|
||||||
|
o allow \r or \n individually to separate HTTP headers instead of the standard "\r\n"; from Charles Kerr.
|
||||||
|
37
http.c
37
http.c
@ -1175,58 +1175,55 @@ evhttp_add_header(struct evkeyvalq *headers,
|
|||||||
int
|
int
|
||||||
evhttp_parse_lines(struct evhttp_request *req, struct evbuffer* buffer)
|
evhttp_parse_lines(struct evhttp_request *req, struct evbuffer* buffer)
|
||||||
{
|
{
|
||||||
u_char *endp;
|
char *line;
|
||||||
int done = 0;
|
int done = 0;
|
||||||
|
|
||||||
struct evkeyvalq* headers = req->input_headers;
|
struct evkeyvalq* headers = req->input_headers;
|
||||||
while ((endp = evbuffer_find(buffer, (u_char *)"\r\n", 2)) != NULL) {
|
while ((line = evbuffer_readline(buffer)) != NULL) {
|
||||||
char *skey, *svalue;
|
char *skey, *svalue;
|
||||||
|
|
||||||
if (strncmp((char *)EVBUFFER_DATA(buffer), "\r\n", 2) == 0) {
|
if (*line == '\0') { /* Last header - Done */
|
||||||
evbuffer_drain(buffer, 2);
|
|
||||||
/* Last header - Done */
|
|
||||||
done = 1;
|
done = 1;
|
||||||
|
free (line);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
*endp = '\0';
|
|
||||||
endp += 2;
|
|
||||||
|
|
||||||
/* Processing of header lines */
|
/* Processing of header lines */
|
||||||
if (req->got_firstline == 0) {
|
if (req->got_firstline == 0) {
|
||||||
switch (req->kind) {
|
switch (req->kind) {
|
||||||
case EVHTTP_REQUEST:
|
case EVHTTP_REQUEST:
|
||||||
if (evhttp_parse_request_line(req,
|
if (evhttp_parse_request_line(req, line) == -1)
|
||||||
(char *)EVBUFFER_DATA(buffer)) == -1)
|
goto error;
|
||||||
return (-1);
|
|
||||||
break;
|
break;
|
||||||
case EVHTTP_RESPONSE:
|
case EVHTTP_RESPONSE:
|
||||||
if (evhttp_parse_response_line(req,
|
if (evhttp_parse_response_line(req, line) == -1)
|
||||||
(char *)EVBUFFER_DATA(buffer)) == -1)
|
goto error;
|
||||||
return (-1);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return (-1);
|
goto error;
|
||||||
}
|
}
|
||||||
req->got_firstline = 1;
|
req->got_firstline = 1;
|
||||||
} else {
|
} else {
|
||||||
/* Regular header */
|
/* Regular header */
|
||||||
svalue = (char *)EVBUFFER_DATA(buffer);
|
svalue = line;
|
||||||
skey = strsep(&svalue, ":");
|
skey = strsep(&svalue, ":");
|
||||||
if (svalue == NULL)
|
if (svalue == NULL)
|
||||||
return (-1);
|
goto error;
|
||||||
|
|
||||||
svalue += strspn(svalue, " ");
|
svalue += strspn(svalue, " ");
|
||||||
|
|
||||||
if (evhttp_add_header(headers, skey, svalue) == -1)
|
if (evhttp_add_header(headers, skey, svalue) == -1)
|
||||||
return (-1);
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Move the uncompleted headers forward */
|
free (line);
|
||||||
evbuffer_drain(buffer, endp - EVBUFFER_DATA(buffer));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (done);
|
return (done);
|
||||||
|
|
||||||
|
error:
|
||||||
|
free (line);
|
||||||
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user