From 3922a5371c59a2fc0cc7c0f1e84c32f9dfc46ae8 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Fri, 14 Jan 2011 23:01:04 -0500 Subject: [PATCH] Host header is now stored per-request instead of globally. This will allow sitemaps generated by hosts with multiple names to be referenced correctly. --- webcit/context_loop.c | 23 +++++++++++++++-------- webcit/webcit.h | 4 +++- webcit/webserver.c | 1 - 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/webcit/context_loop.c b/webcit/context_loop.c index bec8e6122..0979181b4 100644 --- a/webcit/context_loop.c +++ b/webcit/context_loop.c @@ -624,20 +624,25 @@ void Header_HandleContentType(StrBuf *Line, ParsedHttpHdrs *hdr) void Header_HandleHost(StrBuf *Line, ParsedHttpHdrs *hdr) { - if (site_prefix == NULL) { - site_prefix = NewStrBuf(); - StrBufAppendPrintf(site_prefix, "%s://", (is_https ? "https" : "http") ); - StrBufAppendBuf(site_prefix, Line, 0); + if (hdr->HostHeader != NULL) { + FreeStrBuf(&hdr->HostHeader); } + hdr->HostHeader = NewStrBuf(); + StrBufAppendPrintf(hdr->HostHeader, "%s://", (is_https ? "https" : "http") ); + StrBufAppendBuf(hdr->HostHeader, Line, 0); } void Header_HandleXFFHost(StrBuf *Line, ParsedHttpHdrs *hdr) { - if ( (follow_xff) && (site_prefix == NULL)) { - site_prefix = NewStrBuf(); - StrBufAppendPrintf(site_prefix, "http://"); /* this is naive; do something about it */ - StrBufAppendBuf(site_prefix, Line, 0); + if (!follow_xff) return; + + if (hdr->HostHeader != NULL) { + FreeStrBuf(&hdr->HostHeader); } + + hdr->HostHeader = NewStrBuf(); + StrBufAppendPrintf(hdr->HostHeader, "http://"); /* this is naive; do something about it */ + StrBufAppendBuf(hdr->HostHeader, Line, 0); } @@ -783,6 +788,7 @@ HttpDetachModule_CONTEXT (ParsedHttpHdrs *httpreq) { FlushStrBuf(httpreq->PlainArgs); + FlushStrBuf(httpreq->HostHeader); FlushStrBuf(httpreq->this_page); FlushStrBuf(httpreq->PlainArgs); DeleteHash(&httpreq->HTTPHeaders); @@ -797,6 +803,7 @@ HttpDestroyModule_CONTEXT FreeStrBuf(&httpreq->PlainArgs); FreeStrBuf(&httpreq->this_page); FreeStrBuf(&httpreq->PlainArgs); + FreeStrBuf(&httpreq->HostHeader); DeleteHash(&httpreq->HTTPHeaders); } diff --git a/webcit/webcit.h b/webcit/webcit.h index 9a30bede6..5417fe021 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -454,6 +454,7 @@ typedef struct _ParsedHttpHdrs { StrBuf *c_language; StrBuf *this_page; /* URL of current page */ StrBuf *PlainArgs; + StrBuf *HostHeader; HashList *urlstrings; /* variables passed to webcit in a URL */ HashList *HTTPHeaders; /* the headers the client sent us */ @@ -595,6 +596,8 @@ enum { #define num_parms(source) num_tokens(source, '|') #endif +#define site_prefix (WC ? (WC->Hdr->HostHeader) : NULL) + /* Per-session data */ #define WC ((struct wcsession *)pthread_getspecific(MyConKey)) extern pthread_key_t MyConKey; @@ -620,7 +623,6 @@ extern char wizard_filename[]; extern int follow_xff; extern int num_threads_existing; extern int num_threads_executing; -extern StrBuf *site_prefix; void InitialiseSemaphores(void); void begin_critical_section(int which_one); diff --git a/webcit/webserver.c b/webcit/webserver.c index b5973eac8..73f956c31 100644 --- a/webcit/webserver.c +++ b/webcit/webserver.c @@ -24,7 +24,6 @@ int is_https = 0; /* Nonzero if I am an HTTPS service */ int follow_xff = 0; /* Follow X-Forwarded-For: header */ int home_specified = 0; /* did the user specify a homedir? */ int DisableGzip = 0; -StrBuf *site_prefix = NULL; extern pthread_mutex_t SessionListMutex; extern pthread_key_t MyConKey; -- 2.30.2