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)
{
}
{
return this->responsecode;
}
+
+ std::string& GetExtraHeaders()
+ {
+ return this->extraheaders;
+ }
};
#endif
}
}
- 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");
}
{
if ((request_type == "GET") && (uri == "/"))
{
- SendHeaders(index->ContentSize(),200);
+ SendHeaders(index->ContentSize(), 200, "");
this->Write(index->Contents());
}
else
if (!claimed)
{
- SendHeaders(0, 404);
+ SendHeaders(0, 404, "");
log(DEBUG,"Page not claimed, 404");
}
}
}
}
- 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());
}
};
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;
}
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();