Example #1
0
	void SendHeaders(unsigned long size, int response, HTTPHeaders &rheaders)
	{

		WriteData(http_version + " "+ConvToStr(response)+" "+Response(response)+"\r\n");

		time_t local = ServerInstance->Time();
		struct tm *timeinfo = gmtime(&local);
		char *date = asctime(timeinfo);
		date[strlen(date) - 1] = '\0';
		rheaders.CreateHeader("Date", date);

		rheaders.CreateHeader("Server", BRANCH);
		rheaders.SetHeader("Content-Length", ConvToStr(size));

		if (size)
			rheaders.CreateHeader("Content-Type", "text/html");
		else
			rheaders.RemoveHeader("Content-Type");

		/* Supporting Connection: keep-alive causes a whole world of hurt syncronizing timeouts,
		 * so remove it, its not essential for what we need.
		 */
		rheaders.SetHeader("Connection", "Close");

		WriteData(rheaders.GetFormattedHeaders());
		WriteData("\r\n");
	}
Example #2
0
	void SendHeaders(unsigned long size, int response, HTTPHeaders &rheaders)
	{

		WriteData(http_version + " "+ConvToStr(response)+" "+Response(response)+"\r\n");

		rheaders.CreateHeader("Date", InspIRCd::TimeString(ServerInstance->Time(), "%a, %d %b %Y %H:%M:%S GMT", true));
		rheaders.CreateHeader("Server", INSPIRCD_BRANCH);
		rheaders.SetHeader("Content-Length", ConvToStr(size));

		if (size)
			rheaders.CreateHeader("Content-Type", "text/html");
		else
			rheaders.RemoveHeader("Content-Type");

		/* Supporting Connection: keep-alive causes a whole world of hurt syncronizing timeouts,
		 * so remove it, its not essential for what we need.
		 */
		rheaders.SetHeader("Connection", "Close");

		WriteData(rheaders.GetFormattedHeaders());
		WriteData("\r\n");
	}
Example #3
0
void Connection::SendError(int code, const std::string &text, bool fatal = false)
{
	HTTPHeaders empty;
	empty.SetHeader("Content-Type", "text/html");
	std::string data = "<html><head></head><body>" + text + "<br><small>Powered by Hottpd</small></body></html>";
	
	ResponseBackend = NULL;
	this->SendHeaders(data.length(), code, text, empty);

	State = HTTP_SEND_DATA;
	this->Write(data);
	ResponseBufferDone = true;

	// Flush the write buffer now instead of waiting an iteration, since we've written all we need to
	this->FlushWriteBuf();

	if (fatal)
	{
		// Semi-hack. Disabling keepalive means connection is closed ASAP.
		keepalive = false;
	}
}