From 9e9eca797684e57318dde54f5a89a3029181590e Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Wed, 17 Dec 2008 03:34:00 +0100 Subject: [PATCH] Strip the leading slash of the rest string. --- lib/req.c | 11 +++++++++++ lib/req.h | 1 + src/htparser.c | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/lib/req.c b/lib/req.c index 2671159..0ede229 100644 --- a/lib/req.c +++ b/lib/req.c @@ -89,6 +89,17 @@ char *getheader(struct hthead *head, char *name) return(NULL); } +void replrest(struct hthead *head, char *rest) +{ + char *tmp; + + /* Do not free the current rest string yet, so that the new one + * can a subpart of the old one. */ + tmp = head->rest; + head->rest = sstrdup(rest); + free(tmp); +} + void headpreheader(struct hthead *head, const char *name, const char *val) { head->headers = srealloc(head->headers, sizeof(*head->headers) * (head->noheaders + 1)); diff --git a/lib/req.h b/lib/req.h index a3fc0be..942ff35 100644 --- a/lib/req.h +++ b/lib/req.h @@ -17,5 +17,6 @@ void headpreheader(struct hthead *head, const char *name, const char *val); void headappheader(struct hthead *head, const char *name, const char *val); int sendreq(int sock, struct hthead *req); int recvreq(int sock, struct hthead **reqp); +void replrest(struct hthead *head, char *rest); #endif diff --git a/src/htparser.c b/src/htparser.c index c78f064..c0aca2e 100644 --- a/src/htparser.c +++ b/src/htparser.c @@ -369,6 +369,10 @@ static void serve(struct muth *muth, va_list args) goto out; inbuf.b[headoff] = old; bufeat(inbuf, headoff); + /* We strip off the leading slash from the rest string, so + * that multiplexers can parse coherently. */ + if(req->rest[0] == '/') + replrest(req, req->rest + 1); /* * Add metainformation and then send the request to the root -- 2.11.0