]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Stuff for adding extra headers to a response (for Authorization: and Location: etc)
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Tue, 11 Jul 2006 14:38:07 +0000 (14:38 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Tue, 11 Jul 2006 14:38:07 +0000 (14:38 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4333 e03df62e-2008-0410-955e-edbf42e46eb7

src/modules/httpd.h
src/modules/m_httpd.cpp
src/modules/m_httpd_stats.cpp

index 5ac4d0c85fd4ca1bbf8adcc43135ff69f74dc862..ba059dca8e01ea2a8d2f25c1247a737df6167923 100644 (file)
@@ -50,12 +50,13 @@ class HTTPDocument : public classbase
  protected:
        std::stringstream* document;
        int responsecode;
+       std::string extraheaders;
 
  public:
 
        void* sock;
 
-       HTTPDocument(void* opaque, std::stringstream* doc, int response) : document(doc), responsecode(response), sock(opaque)
+       HTTPDocument(void* opaque, std::stringstream* doc, int response, const std::string &extra) : document(doc), responsecode(response), extraheaders(extra), sock(opaque)
        {
        }
 
@@ -73,6 +74,11 @@ class HTTPDocument : public classbase
        {
                return this->responsecode;
        }
+
+       std::string& GetExtraHeaders()
+       {
+               return this->extraheaders;
+       }
 };
 
 #endif
index dc6a7f4185ab7b0074cb42825a9adcd5434e63f3..3d47ed0427969e84364be7d6d3a0ddca145e2459 100644 (file)
@@ -164,11 +164,12 @@ class HttpSocket : public InspSocket
                }
        }
 
-       void SendHeaders(unsigned long size, int response)
+       void SendHeaders(unsigned long size, int response, std::string &extraheaders)
        {
                struct tm *timeinfo = localtime(&TIME);
                this->Write("HTTP/1.1 "+ConvToStr(response)+" "+Response(response)+"\r\nDate: ");
                this->Write(asctime(timeinfo));
+               this->Write(extraheaders);
                this->Write("Server: InspIRCd/m_httpd.so/1.1\r\nContent-Length: "+ConvToStr(size)+
                                "\r\nConnection: close\r\nContent-Type: text/html\r\n\r\n");
        }
@@ -202,7 +203,7 @@ class HttpSocket : public InspSocket
                                {
                                        if ((request_type == "GET") && (uri == "/"))
                                        {
-                                               SendHeaders(index->ContentSize(),200);
+                                               SendHeaders(index->ContentSize(), 200, "");
                                                this->Write(index->Contents());
                                        }
                                        else
@@ -214,7 +215,7 @@ class HttpSocket : public InspSocket
 
                                                if (!claimed)
                                                {
-                                                       SendHeaders(0, 404);
+                                                       SendHeaders(0, 404, "");
                                                        log(DEBUG,"Page not claimed, 404");
                                                }
                                        }
@@ -233,10 +234,10 @@ class HttpSocket : public InspSocket
                }
        }
 
-       void Page(std::stringstream* n, int response)
+       void Page(std::stringstream* n, int response, std::string& extraheaders)
        {
                log(DEBUG,"Sending page");
-               SendHeaders(n->str().length(),response);
+               SendHeaders(n->str().length(), response, extraheaders);
                this->Write(n->str());
        }
 };
@@ -291,7 +292,7 @@ class ModuleHttp : public Module
                claimed = true;
                HTTPDocument* doc = (HTTPDocument*)request->GetData();
                HttpSocket* sock = (HttpSocket*)doc->sock;
-               sock->Page(doc->GetDocument(), doc->GetResponseCode());
+               sock->Page(doc->GetDocument(), doc->GetResponseCode(), doc->GetExtraHeaders());
                return NULL;
        }
 
index 3d02c68b5f198a2d03325cf2c0b868ca29114669..894aeed5b3a344451f97a9632c44e300a8ebc471 100644 (file)
@@ -52,7 +52,7 @@ class ModuleHttpStats : public Module
                        data << "<html><h1>Chickens</h1></html>";
 
                        HTTPRequest* http = (HTTPRequest*)event->GetData();
-                       HTTPDocument response(http->sock, &data, 200);
+                       HTTPDocument response(http->sock, &data, 200, "X-Powered-By: m_http_stats.so\r\n");
                        Request req((char*)&response, (Module*)this, event->GetSource());
                        req.Send();