From b38337ef8a742807b25e9811e7420fe649de6fb4 Mon Sep 17 00:00:00 2001 From: phk Date: Thu, 6 Apr 2006 07:50:05 +0000 Subject: [PATCH] Add a function to (re)build a HTTP request or response into an sbuf. Enable Id keyword git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@120 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 2 ++ varnish-cache/bin/varnishd/cache_httpd.c | 38 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index cc0742c6..5c306caa 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -3,6 +3,7 @@ */ struct event_base; +struct sbuf; #ifdef EV_TIMEOUT struct worker { @@ -27,6 +28,7 @@ void VBE_ClosedFd(void *ptr); /* cache_httpd.c */ void HttpdAnalyze(struct sess *sp, int rr); void HttpdGetHead(struct sess *sp, struct event_base *eb, sesscb_f *func); +void HttpdBuildSbuf(int resp, int filter, struct sbuf *sb, struct sess *sp); /* cache_main.c */ pthread_mutex_t sessmtx; diff --git a/varnish-cache/bin/varnishd/cache_httpd.c b/varnish-cache/bin/varnishd/cache_httpd.c index c8897a71..b820455f 100644 --- a/varnish-cache/bin/varnishd/cache_httpd.c +++ b/varnish-cache/bin/varnishd/cache_httpd.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "libvarnish.h" #include "shmlog.h" @@ -181,3 +182,40 @@ HttpdGetHead(struct sess *sp, struct event_base *eb, sesscb_f *func) event_base_set(eb, sp->rd_e); event_add(sp->rd_e, NULL); /* XXX: timeout */ } + +/*--------------------------------------------------------------------*/ + +void +HttpdBuildSbuf(int resp, int filter, struct sbuf *sb, struct sess *sp) +{ + + sbuf_clear(sb); + assert(sb != NULL); + if (resp) { + sbuf_cat(sb, sp->http.proto); + sbuf_cat(sb, " "); + sbuf_cat(sb, sp->http.status); + sbuf_cat(sb, " "); + sbuf_cat(sb, sp->http.response); + } else { + sbuf_cat(sb, sp->http.req); + sbuf_cat(sb, " "); + sbuf_cat(sb, sp->http.url); + sbuf_cat(sb, " "); + sbuf_cat(sb, sp->http.proto); + } + sbuf_cat(sb, "\r\n"); +#define HTTPH(a, b, c, d, e, f, g) \ + do { \ + if ((!filter || d) && sp->http.b != NULL) { \ + sbuf_cat(sb, a ": "); \ + sbuf_cat(sb, sp->http.b); \ + sbuf_cat(sb, "\r\n"); \ + } \ + } while (0); +#include "http_headers.h" +#undef HTTPH + sbuf_cat(sb, "\r\n"); + sbuf_finish(sb); + +} -- 2.39.5