Ejemplo n.º 1
0
string HttpResponse::generateTraceResponse(HttpRequest* req)
{
	addHeaderValue("Server", "FFEAD 1.1");
	string resp;
	resp = (httpVersion + " " + statusCode + " " + statusMsg + "\r\n");
	map<string,string>::iterator it;
	for(it=headers.begin();it!=headers.end();++it)
	{
		resp += it->first + ": " + it->second + "\r\n";
	}
	for (int var = 0; var < (int)this->cookies.size(); var++)
	{
		resp += "Set-Cookie: " + this->cookies.at(var) + "\r\n";
	}
	resp += "\r\n";
	if(req!=NULL)
	{
		map<string,string>::iterator it;
		for(it=headers.begin();it!=req->getHeaders().end();++it)
		{
			resp += it->first + ": " + it->second + "\r\n";
		}
	}
	return resp;
}
Ejemplo n.º 2
0
MIMEHeader& MIMEHeader::operator=(const MIMEHeader& rhs)
{
    if (&rhs != this)
    {
        clearHeaderValueList();

        m_name = rhs.m_name;

        LISTPOSITION pos = rhs.m_headerValues.GetHeadPosition();

        while(pos)
        {
            MIMEHeaderValue* pHdrValue = 
                (MIMEHeaderValue*)rhs.m_headerValues.GetNext(pos);

            if (pHdrValue)
            {
                MIMEHeaderValue* pNewHdrValue = 
                    new MIMEHeaderValue(*pHdrValue);
                
                if (pNewHdrValue)
                {
                    addHeaderValue(pNewHdrValue);
                }
            }
        }
    }

    return *this;
}
Ejemplo n.º 3
0
string HttpResponse::generateOptionsResponse()
{
	addHeaderValue("Server", "FFEAD 1.1");
	string resp;
	resp = (httpVersion + " " + statusCode + " " + statusMsg + "\r\n");
	map<string,string>::iterator it;
	for(it=headers.begin();it!=headers.end();++it)
	{
		resp += it->first + ": " + it->second + "\r\n";
	}
	for (int var = 0; var < (int)this->cookies.size(); var++)
	{
		resp += "Set-Cookie: " + this->cookies.at(var) + "\r\n";
	}
	resp += "Allow: OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE\r\n";
	resp += "\r\n";
	return resp;
}
Ejemplo n.º 4
0
bool HttpParserImpl::parseHeaderLine(const char* line, const char* line_end)
{
    const char* p_line = line;
    const char* p_end = line_end;
    if(!str_buf_.empty()) {
        str_buf_.append(line, line_end);
        p_line = str_buf_.c_str();
        p_end = p_line + str_buf_.length();
    }
    
    std::string str_name;
    std::string str_value;
    const char* p = std::find(p_line, p_end, ':');
    if(p == p_end) {
        clearBuffer();
        return false;
    }
    str_name.assign(p_line, p);
    p_line = p + 1;
    str_value.assign(p_line, p_end);
    clearBuffer();
    addHeaderValue(str_name, str_value);
    return true;
}
Ejemplo n.º 5
0
string HttpResponse::generateHeadResponse()
{
	addHeaderValue("Server", "FFEAD 1.1");
	bool isTE = isHeaderValue("Transfer-Encoding", "chunked");
	bool isCEGzip = isHeaderValue("Content-Encoding", "gzip");
	bool isCEDef = isHeaderValue("Content-Encoding", "deflate");
	string resp, boundary;
	if(this->contentList.size()>0)
	{
		content = "";
		boundary = "FFEAD_SERVER_" + CastUtil::lexical_cast<string>(Timer::getCurrentTime());
		for (int var = 0; var < (int)contentList.size(); ++var) {
			content += "--" + boundary + "\r\n";
			map<string,string> headers = contentList.at(var).getHeaders();
			map<string,string>::iterator it;
			for(it=headers.begin();it!=headers.end();++it)
			{
				content += it->first + ": " + it->second + "\r\n";
			}
			content += "\r\n";
			content += contentList.at(var).getContent();
			content += "\r\n";
		}
		content += "--" + boundary + "--\r\n";
	}
	resp = (httpVersion + " " + statusCode + " " + statusMsg + "\r\n");
	if(this->getHeader("Content-Type")=="" && this->contentList.size()>0)
	{
		this->addHeaderValue("Content-Type", "multipart/mixed");
	}
	if(this->getHeader("Content-Type")!="" && boundary!="")
	{
		headers["Content-Type"] += "; boundary=" + boundary;
	}
	if(!isTE && !compressed)
	{
		if(isCEGzip)
		{
			if(this->content!="")
			{
				this->content = CompressionUtil::gzipCompress(this->content, true);
			}
		}
		if(isCEDef)
		{
			if(this->content!="")
			{
				this->content = CompressionUtil::zlibCompress(this->content, true);
			}
		}
	}
	if(!isTE && this->content!="")
	{
		headers["Content-Length"] = CastUtil::lexical_cast<string>((int)content.length());
	}
	map<string,string>::iterator it;
	for(it=headers.begin();it!=headers.end();++it)
	{
		resp += it->first + ": " + it->second + "\r\n";
	}
	for (int var = 0; var < (int)this->cookies.size(); var++)
	{
		resp += "Set-Cookie: " + this->cookies.at(var) + "\r\n";
	}
	resp += "\r\n";
	return resp;
}
Ejemplo n.º 6
0
void
MIMEHeader::addHeaderValue(const char* pValue)
{
    addHeaderValue(new MIMEHeaderValue(pValue));
}