Commit a3df20be authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Strengthen HTTP parsing


git-svn-id: http://www.varnish-cache.org/svn/trunk@357 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 99446dd6
...@@ -210,9 +210,11 @@ http_Dissect(struct http *hp, int fd, int rr) ...@@ -210,9 +210,11 @@ http_Dissect(struct http *hp, int fd, int rr)
{ {
char *p, *q, *r; char *p, *q, *r;
for (p = hp->s ; p < hp->v && isspace(*p); p++)
continue;
assert(hp->t != NULL); assert(hp->t != NULL);
assert(hp->s < hp->t);
assert(hp->t <= hp->v);
for (p = hp->s ; isspace(*p); p++)
continue;
if (rr == 1) { if (rr == 1) {
/* First, isolate and possibly identify request type */ /* First, isolate and possibly identify request type */
hp->req = p; hp->req = p;
...@@ -228,22 +230,25 @@ http_Dissect(struct http *hp, int fd, int rr) ...@@ -228,22 +230,25 @@ http_Dissect(struct http *hp, int fd, int rr)
while (!isspace(*p)) while (!isspace(*p))
p++; p++;
VSLR(SLT_URL, fd, hp->url, p); VSLR(SLT_URL, fd, hp->url, p);
*p++ = '\0';
/* Finally, look for protocol, if any */
while (isspace(*p) && *p != '\n')
p++;
hp->proto = p;
if (*p != '\n') { if (*p != '\n') {
while (!isspace(*p)) *p++ = '\0';
/* Finally, look for protocol, if any */
while (isspace(*p) && *p != '\n')
p++; p++;
if (*p != '\n') {
hp->proto = p;
while (!isspace(*p))
p++;
if (*p != '\n')
*p++ = '\0';
while (isspace(*p) && *p != '\n')
p++;
}
} }
VSLR(SLT_Protocol, fd, hp->proto, p);
*p++ = '\0'; *p++ = '\0';
if (hp->proto != NULL)
while (isspace(*p) && *p != '\n') VSLR(SLT_Protocol, fd, hp->proto, p);
p++;
p++;
} else { } else {
/* First, protocol */ /* First, protocol */
hp->proto = p; hp->proto = p;
...@@ -369,6 +374,7 @@ http_read_f(int fd, short event, void *arg) ...@@ -369,6 +374,7 @@ http_read_f(int fd, short event, void *arg)
if (!http_header_complete(hp)) if (!http_header_complete(hp))
return; return;
assert(hp->t != NULL);
event_del(&hp->ev); event_del(&hp->ev);
if (hp->callback != NULL) if (hp->callback != NULL)
hp->callback(hp->arg, 1); hp->callback(hp->arg, 1);
...@@ -391,6 +397,7 @@ http_RecvHead(struct http *hp, int fd, struct event_base *eb, http_callback_f *f ...@@ -391,6 +397,7 @@ http_RecvHead(struct http *hp, int fd, struct event_base *eb, http_callback_f *f
hp->v = hp->s + l; hp->v = hp->s + l;
hp->t = hp->s; hp->t = hp->s;
if (http_header_complete(hp)) { if (http_header_complete(hp)) {
assert(func != NULL);
func(arg, 1); func(arg, 1);
return; return;
} }
...@@ -453,15 +460,21 @@ http_BuildSbuf(int fd, enum http_build mode, struct sbuf *sb, struct http *hp) ...@@ -453,15 +460,21 @@ http_BuildSbuf(int fd, enum http_build mode, struct sbuf *sb, struct http *hp)
sbuf_cat(sb, hp->req); sbuf_cat(sb, hp->req);
sbuf_cat(sb, " "); sbuf_cat(sb, " ");
sbuf_cat(sb, hp->url); sbuf_cat(sb, hp->url);
sbuf_cat(sb, " "); if (hp->proto != NULL) {
sbuf_cat(sb, hp->proto); sbuf_cat(sb, " ");
sbuf_cat(sb, hp->proto);
}
sup = 2; sup = 2;
break; break;
case Build_Fetch: case Build_Fetch:
sbuf_cat(sb, "GET "); sbuf_cat(sb, "GET ");
sbuf_cat(sb, hp->url); sbuf_cat(sb, hp->url);
sbuf_cat(sb, " "); if (hp->proto != NULL) {
sbuf_cat(sb, hp->proto); sbuf_cat(sb, " ");
sbuf_cat(sb, hp->proto);
} else {
sbuf_cat(sb, " HTTP/1.1");
}
sup = 1; sup = 1;
break; break;
default: default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment