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

Add HTTP response headers and processing.


git-svn-id: http://www.varnish-cache.org/svn/trunk@111 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 4739b0ba
......@@ -15,7 +15,7 @@ void VBE_Pass(struct sess *sp);
void VBE_ClosedFd(void *ptr);
/* cache_httpd.c */
void HttpdAnalyze(struct sess *sp);
void HttpdAnalyze(struct sess *sp, int rr);
void HttpdGetHead(struct sess *sp, struct event_base *eb, sesscb_f *func);
/* cache_main.c */
......
......@@ -21,7 +21,7 @@
/*--------------------------------------------------------------------*/
void
HttpdAnalyze(struct sess *sp)
HttpdAnalyze(struct sess *sp, int rr)
{
char *p, *q, *r;
......@@ -29,37 +29,68 @@ HttpdAnalyze(struct sess *sp)
memset(&sp->http, 0, sizeof sp->http);
/* First, isolate and possibly identify request type */
sp->http.req = sp->rcv;
for (p = sp->rcv; isalpha(*p); p++)
;
VSLR(SLT_Request, sp->fd, sp->http.req, p);
*p++ = '\0';
if (rr == 1) {
/* First, isolate and possibly identify request type */
sp->http.req = sp->rcv;
for (p = sp->rcv; isalpha(*p); p++)
;
VSLR(SLT_Request, sp->fd, sp->http.req, p);
*p++ = '\0';
/* Next find the URI */
while (isspace(*p))
p++;
sp->http.url = p;
while (!isspace(*p))
p++;
VSLR(SLT_URL, sp->fd, sp->http.url, p);
*p++ = '\0';
/* Next find the URI */
while (isspace(*p))
p++;
sp->http.url = p;
while (!isspace(*p))
p++;
VSLR(SLT_URL, sp->fd, sp->http.url, p);
*p++ = '\0';
/* Finally, look for protocol, if any */
while (isspace(*p) && *p != '\n')
/* Finally, look for protocol, if any */
while (isspace(*p) && *p != '\n')
p++;
sp->http.proto = p;
if (*p != '\n') {
while (!isspace(*p))
p++;
}
VSLR(SLT_Protocol, sp->fd, sp->http.proto, p);
*p++ = '\0';
while (isspace(*p) && *p != '\n')
p++;
p++;
sp->http.proto = p;
if (*p != '\n') {
} else {
/* First, protocol */
sp->http.proto = sp->rcv;
p = sp->rcv;
while (!isspace(*p))
p++;
}
VSLR(SLT_Protocol, sp->fd, sp->http.proto, p);
*p++ = '\0';
*p++ = '\0';
VSLR(SLT_Protocol, sp->fd, sp->http.proto, p);
while (isspace(*p) && *p != '\n')
/* Next find the status */
while (isspace(*p))
p++;
sp->http.status = p;
while (!isspace(*p))
p++;
VSLR(SLT_Status, sp->fd, sp->http.status, p);
*p++ = '\0';
/* Next find the response */
while (isspace(*p))
p++;
sp->http.response = p;
while (*p != '\n')
p++;
for (q = p; q > sp->http.response && isspace(q[-1]); q--)
continue;
*q = '\0';
VSLR(SLT_Response, sp->fd, sp->http.response, q);
p++;
}
p++;
if (*p == '\r')
p++;
......@@ -81,7 +112,10 @@ HttpdAnalyze(struct sess *sp)
continue; \
}
#define HTTPH(a, b, c, d, e, f, g) W(a ":", b, p, q, sp)
#define HTTPH(a, b, c, d, e, f, g) \
if (c & rr) { \
W(a ":", b, p, q, sp); \
}
#include "http_headers.h"
#undef HTTPH
#undef W
......
......@@ -25,7 +25,7 @@ PassReturn(struct sess *sp)
{
HERE();
HttpdAnalyze(sp);
HttpdAnalyze(sp, 2);
}
/*--------------------------------------------------------------------*/
......@@ -52,7 +52,7 @@ PassSession(struct sess *sp)
sbuf_cat(sb, "\r\n");
#define HTTPH(a, b, c, d, e, f, g) \
do { \
if (c && sp->http.b != NULL) { \
if (d && sp->http.b != NULL) { \
sbuf_cat(sb, a ": "); \
sbuf_cat(sb, sp->http.b); \
sbuf_cat(sb, "\r\n"); \
......@@ -62,7 +62,6 @@ PassSession(struct sess *sp)
#undef HTTPH
sbuf_cat(sb, "\r\n");
sbuf_finish(sb);
printf("REQ: <%s>\n", sbuf_data(sb));
i = write(fd, sbuf_data(sb), sbuf_len(sb));
assert(i == sbuf_len(sb));
......
......@@ -75,7 +75,6 @@ PipeSession(struct sess *sp)
#undef HTTPH
sbuf_cat(sb, "\r\n");
sbuf_finish(sb);
printf("REQ: <%s>\n", sbuf_data(sb));
i = write(fd, sbuf_data(sb), sbuf_len(sb));
assert(i == sbuf_len(sb));
......
......@@ -31,7 +31,7 @@ CacheWorker(void *priv __unused)
sp->vcl = GetVCL();
AZ(pthread_mutex_unlock(&sessmtx));
HttpdAnalyze(sp);
HttpdAnalyze(sp, 1);
sp->backend = sp->vcl->default_backend;
/* Call the VCL program */
......
......@@ -3,8 +3,8 @@
*
* a Http header name
* b session field name
* c PassThrough handling (0=remove, 1=pass)
* d unused
* c Request(1)/Response(2) bitfield
* d Pass header
* e unused
* f unused
* g unused
......@@ -12,24 +12,35 @@
* a b c d e f g
*--------------------------------------------------------------------
*/
HTTPH("Accept-Charset", H_Accept_Charset, 1, 0, 0, 0, 0)
HTTPH("Accept-Encoding", H_Accept_Encoding, 1, 0, 0, 0, 0)
HTTPH("Accept-Language", H_Accept_Language, 1, 0, 0, 0, 0)
HTTPH("Accept", H_Accept, 1, 0, 0, 0, 0)
HTTPH("Authorization", H_Authorization, 1, 0, 0, 0, 0)
HTTPH("Connection", H_Connection, 0, 0, 0, 0, 0)
HTTPH("Expect", H_Expect, 1, 0, 0, 0, 0)
HTTPH("From", H_From, 1, 0, 0, 0, 0)
HTTPH("Host", H_Host, 1, 0, 0, 0, 0)
HTTPH("If-Match", H_If_Match, 1, 0, 0, 0, 0)
HTTPH("If-Modified-Since", H_If_Modified_Since, 1, 0, 0, 0, 0)
HTTPH("If-None-Match", H_If_None_Match, 1, 0, 0, 0, 0)
HTTPH("If-Range", H_If_Range, 1, 0, 0, 0, 0)
HTTPH("If-Unmodified-Since", H_If_Unmodifed_Since, 1, 0, 0, 0, 0)
HTTPH("Keep-Alive", H_Keep_Alive, 0, 0, 0, 0, 0)
HTTPH("Max-Forwards", H_Max_Forwards, 1, 0, 0, 0, 0)
HTTPH("Proxy-Authorization", H_Proxy_Authorization, 1, 0, 0, 0, 0)
HTTPH("Range", H_Range, 1, 0, 0, 0, 0)
HTTPH("Referer", H_Referer, 1, 0, 0, 0, 0)
HTTPH("TE", H_TE, 1, 0, 0, 0, 0)
HTTPH("User-Agent", H_User_Agent, 1, 0, 0, 0, 0)
HTTPH("Connection", H_Connection, 3, 0, 0, 0, 0)
HTTPH("Keep-Alive", H_Keep_Alive, 3, 0, 0, 0, 0)
HTTPH("Accept-Charset", H_Accept_Charset, 1, 1, 0, 0, 0)
HTTPH("Accept-Encoding", H_Accept_Encoding, 1, 1, 0, 0, 0)
HTTPH("Accept-Language", H_Accept_Language, 1, 1, 0, 0, 0)
HTTPH("Accept", H_Accept, 1, 1, 0, 0, 0)
HTTPH("Authorization", H_Authorization, 1, 1, 0, 0, 0)
HTTPH("Expect", H_Expect, 1, 1, 0, 0, 0)
HTTPH("From", H_From, 1, 1, 0, 0, 0)
HTTPH("Host", H_Host, 1, 1, 0, 0, 0)
HTTPH("If-Match", H_If_Match, 1, 1, 0, 0, 0)
HTTPH("If-Modified-Since", H_If_Modified_Since, 1, 1, 0, 0, 0)
HTTPH("If-None-Match", H_If_None_Match, 1, 1, 0, 0, 0)
HTTPH("If-Range", H_If_Range, 1, 1, 0, 0, 0)
HTTPH("If-Unmodified-Since", H_If_Unmodifed_Since, 1, 1, 0, 0, 0)
HTTPH("Max-Forwards", H_Max_Forwards, 1, 1, 0, 0, 0)
HTTPH("Proxy-Authorization", H_Proxy_Authorization, 1, 1, 0, 0, 0)
HTTPH("Range", H_Range, 1, 1, 0, 0, 0)
HTTPH("Referer", H_Referer, 1, 1, 0, 0, 0)
HTTPH("TE", H_TE, 1, 1, 0, 0, 0)
HTTPH("User-Agent", H_User_Agent, 1, 1, 0, 0, 0)
HTTPH("Server", H_Server, 2, 0, 0, 0, 0)
HTTPH("Content-Type", H_Content_Type, 2, 0, 0, 0, 0)
HTTPH("Date", H_Date, 2, 0, 0, 0, 0)
HTTPH("Last-Modified", H_Last_Modified, 2, 0, 0, 0, 0)
HTTPH("Accept-Ranges", H_Accept_Ranges, 2, 0, 0, 0, 0)
HTTPH("Content-Length", H_Content_Length, 2, 0, 0, 0, 0)
HTTPH("Cache-Control", H_Cache_Control, 2, 0, 0, 0, 0)
HTTPH("Vary", H_Vary, 2, 0, 0, 0, 0)
HTTPH("Expires", H_Expires, 2, 0, 0, 0, 0)
......@@ -12,6 +12,8 @@ SLTM(SessionOpen)
SLTM(SessionClose)
SLTM(ClientAddr)
SLTM(Request)
SLTM(Response)
SLTM(Status)
SLTM(URL)
SLTM(Protocol)
SLTM(HD_Unknown)
......
......@@ -31,6 +31,8 @@ struct httphdr {
const char *req;
const char *url;
const char *proto;
const char *status;
const char *response;
#define HTTPH(a, b, c, d, e, f, g) const char *b;
#include <http_headers.h>
#undef HTTPH
......
......@@ -412,14 +412,16 @@ vcl_output_lang_h(FILE *f)
fputs(" const char *req;\n", f);
fputs(" const char *url;\n", f);
fputs(" const char *proto;\n", f);
fputs(" const char *status;\n", f);
fputs(" const char *response;\n", f);
fputs("#define HTTPH(a, b, c, d, e, f, g) const char *b;\n", f);
fputs("/*\n", f);
fputs(" * $Id$\n", f);
fputs(" *\n", f);
fputs(" * a Http header name\n", f);
fputs(" * b session field name\n", f);
fputs(" * c PassThrough handling (0=remove, 1=pass)\n", f);
fputs(" * d unused\n", f);
fputs(" * c Request(1)/Response(2) bitfield\n", f);
fputs(" * d Pass header\n", f);
fputs(" * e unused\n", f);
fputs(" * f unused\n", f);
fputs(" * g unused\n", f);
......@@ -427,27 +429,38 @@ vcl_output_lang_h(FILE *f)
fputs(" * a b c d e f g \n", f);
fputs(" *--------------------------------------------------------------------\n", f);
fputs(" */\n", f);
fputs("HTTPH(\"Accept-Charset\", H_Accept_Charset, 1, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"Accept-Encoding\", H_Accept_Encoding, 1, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"Accept-Language\", H_Accept_Language, 1, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"Accept\", H_Accept, 1, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"Authorization\", H_Authorization, 1, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"Connection\", H_Connection, 0, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"Expect\", H_Expect, 1, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"From\", H_From, 1, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"Host\", H_Host, 1, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"If-Match\", H_If_Match, 1, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"If-Modified-Since\", H_If_Modified_Since, 1, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"If-None-Match\", H_If_None_Match, 1, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"If-Range\", H_If_Range, 1, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"If-Unmodified-Since\", H_If_Unmodifed_Since, 1, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"Keep-Alive\", H_Keep_Alive, 0, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"Max-Forwards\", H_Max_Forwards, 1, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"Proxy-Authorization\", H_Proxy_Authorization, 1, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"Range\", H_Range, 1, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"Referer\", H_Referer, 1, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"TE\", H_TE, 1, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"User-Agent\", H_User_Agent, 1, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"Connection\", H_Connection, 3, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"Keep-Alive\", H_Keep_Alive, 3, 0, 0, 0, 0)\n", f);
fputs("\n", f);
fputs("HTTPH(\"Accept-Charset\", H_Accept_Charset, 1, 1, 0, 0, 0)\n", f);
fputs("HTTPH(\"Accept-Encoding\", H_Accept_Encoding, 1, 1, 0, 0, 0)\n", f);
fputs("HTTPH(\"Accept-Language\", H_Accept_Language, 1, 1, 0, 0, 0)\n", f);
fputs("HTTPH(\"Accept\", H_Accept, 1, 1, 0, 0, 0)\n", f);
fputs("HTTPH(\"Authorization\", H_Authorization, 1, 1, 0, 0, 0)\n", f);
fputs("HTTPH(\"Expect\", H_Expect, 1, 1, 0, 0, 0)\n", f);
fputs("HTTPH(\"From\", H_From, 1, 1, 0, 0, 0)\n", f);
fputs("HTTPH(\"Host\", H_Host, 1, 1, 0, 0, 0)\n", f);
fputs("HTTPH(\"If-Match\", H_If_Match, 1, 1, 0, 0, 0)\n", f);
fputs("HTTPH(\"If-Modified-Since\", H_If_Modified_Since, 1, 1, 0, 0, 0)\n", f);
fputs("HTTPH(\"If-None-Match\", H_If_None_Match, 1, 1, 0, 0, 0)\n", f);
fputs("HTTPH(\"If-Range\", H_If_Range, 1, 1, 0, 0, 0)\n", f);
fputs("HTTPH(\"If-Unmodified-Since\", H_If_Unmodifed_Since, 1, 1, 0, 0, 0)\n", f);
fputs("HTTPH(\"Max-Forwards\", H_Max_Forwards, 1, 1, 0, 0, 0)\n", f);
fputs("HTTPH(\"Proxy-Authorization\", H_Proxy_Authorization, 1, 1, 0, 0, 0)\n", f);
fputs("HTTPH(\"Range\", H_Range, 1, 1, 0, 0, 0)\n", f);
fputs("HTTPH(\"Referer\", H_Referer, 1, 1, 0, 0, 0)\n", f);
fputs("HTTPH(\"TE\", H_TE, 1, 1, 0, 0, 0)\n", f);
fputs("HTTPH(\"User-Agent\", H_User_Agent, 1, 1, 0, 0, 0)\n", f);
fputs("\n", f);
fputs("HTTPH(\"Server\", H_Server, 2, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"Content-Type\", H_Content_Type, 2, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"Date\", H_Date, 2, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"Last-Modified\", H_Last_Modified, 2, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"Accept-Ranges\", H_Accept_Ranges, 2, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"Content-Length\", H_Content_Length, 2, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"Cache-Control\", H_Cache_Control, 2, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"Vary\", H_Vary, 2, 0, 0, 0, 0)\n", f);
fputs("HTTPH(\"Expires\", H_Expires, 2, 0, 0, 0, 0)\n", f);
fputs("#undef HTTPH\n", f);
fputs(" const char *uhdr[VCA_UNKNOWNHDR];\n", f);
fputs(" unsigned nuhdr;\n", f);
......
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