Host header is now stored per-request instead of globally.
authorArt Cancro <ajc@citadel.org>
Sat, 15 Jan 2011 04:01:04 +0000 (23:01 -0500)
committerWilfried Goesgens <dothebart@citadel.org>
Sun, 4 Sep 2011 13:56:23 +0000 (13:56 +0000)
This will allow sitemaps generated by hosts with multiple names
to be referenced correctly.

webcit/context_loop.c
webcit/webcit.h
webcit/webserver.c

index bec8e6122d30280f1efa8b512f3cbb4a5adcc3d7..0979181b4364c08f02723ef08aa33494c8e6127f 100644 (file)
@@ -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);
 
 }
index 9a30bede6ceced9bbe1624ecf7bd77922b23b03a..5417fe0213c96e2055ca6fc40ca69dac7f6bd8a8 100644 (file)
@@ -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);
index b5973eac8371edd713247c914aec997419083567..73f956c31af193871dbc825111b76bd0981a4d9d 100644 (file)
@@ -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;