本文整理汇总了C++中HttpHeader::addHeaderLine方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpHeader::addHeaderLine方法的具体用法?C++ HttpHeader::addHeaderLine怎么用?C++ HttpHeader::addHeaderLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpHeader
的用法示例。
在下文中一共展示了HttpHeader::addHeaderLine方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
bool
HttpProxyFunctions::fetchThruProxy( const URL& url,
HttpHeader* outHead,
HttpBody* outBody,
ParserThread* myThread,
HttpVariableContainer* myVar) {
URLFetcherNoSSL fetcher;
// return value, true if fetch is successfull
bool ok = false;
const char* squid_prop = Properties::getProperty("INTERNAL_SQUID_URL");
// no need to do proxy if we know about https
if ( ! myVar->https && squid_prop != NULL ) {
fetcher.setProxyAddress( squid_prop );
const uint32 proxyTimeout = Properties::getUint32Property(
"PROXY_TIMEOUT", 60000 );
mc2dbg << "[HttpProxyFunc]: Going to fetch: "
<< fetcher.getProxyAddress() + url.getSpec()
<< endl;
HttpHeader fetHead;
HttpHeader extraHeaders;
extraHeaders.addHeaderLine(
X_WF_ID, myThread->getGroup()->getServerInstanceStr() );
URLFetcherNoSSL::dbPair_t ret = fetcher.get(
fetHead, url, proxyTimeout, &extraHeaders );
if ( (ret.first == HttpCode::OK ||
ret.first == HttpCode::NOT_FOUND ||
ret.first == HttpCode::SERVICE_UNAVAILABLE) &&
ret.second != NULL ) {
outBody->setBody( ret.second->getBufferAddress(),
ret.second->getBufferSize() );
const MC2String* hitOrMissTmp = fetHead.getHeaderValue( &X_CACHE );
MC2String hitOrMiss = hitOrMissTmp ? *hitOrMissTmp : "";
mc2dbg << "[HttpProxyFunc]: proxy fetch successful "
<< hitOrMiss << endl;
ok = true;
// Copy fetHead headers into outHead
// ARRGH! squid supports only HTTP 1.0 not 1.1 as we do.
outHead->setStartLine( ret.first );
// Remove confusing proxy headers.
fetHead.deleteHeaderLine( &PROXY_CONNECTION );
fetHead.deleteHeaderLine( &CONNECTION );
fetHead.deleteHeaderLine( &KEEP_ALIVE );
fetHead.deleteHeaderLine( &X_CACHE );
fetHead.deleteHeaderLine( &AGE );
fetHead.deleteHeaderLine( &TRANSFER_ENCODING ); // chunked
const HttpHeader::HeaderMap& h = fetHead.getHeaderMap();
for ( HttpHeader::HeaderMap::const_iterator it = h.begin() ;
it != h.end(); ++it )
{
outHead->addHeaderLine( it->first, *it->second );
}
} else {
mc2dbg << "[HttpProxyFunc]: proxy fetch unsuccessfull: "
<< ret.first<< endl;
}
// might still be allocated
delete ret.second;
}
return ok;
}
示例2: serverURLStr
int
ParserCWHandler::getURL( const MC2String& urlStr,
const MC2String& postData,
uint32 peerIP, uint32 fromByte, uint32 toByte,
LangTypes::language_t clientLang,
const HttpHeader* inHeaders,
HttpHeader& outHeaders, MC2String& reply,
uint32& startByte, uint32& endByte )
{
uint32 startTime = TimeUtility::getCurrentTime();
// Work with url
MC2String serverURLStr( urlStr );
mc2dbg2 << "serverURLStr " << serverURLStr << endl;
updateRequest( serverURLStr, clientLang );
bool fetchedThruProxy = false;
if ( serverURLStr.find( "://sendThruProxyServer" ) != MC2String::npos ) {
// This url should be fetched thru the proxy server
// Remove 'sendThruProxyServer' from URL
STLStringUtility::replaceString( serverURLStr,
"://sendThruProxyServer/",
"://" );
URL url(serverURLStr);
HttpBody outBody;
HttpVariableContainer myVar;
myVar.https = ( serverURLStr.find( "https://" ) != MC2String::npos );
// Fetch the url thru proxy server. If proxy fails it will be fetched without
// proxy below.
fetchedThruProxy =
HttpProxyFunctions::fetchThruProxy( url, &outHeaders, &outBody, m_thread, &myVar );
if ( fetchedThruProxy ) {
// Successfully fetched thru proxy
reply.append( outBody.getBody(), outBody.getBodyLength() );
}
}
// Work with url
mc2dbg2 << "serverURLStr " << serverURLStr << endl;
updateRequest( serverURLStr, clientLang );
URL url2( serverURLStr );
int ures = 0;
uint32 timeout = Properties::getUint32Property( "CW_TIMEOUT",
5000 );
if ( ! fetchedThruProxy ) {
if ( serverURLStr.find( "internalInThisProcess" ) != MC2String::npos ) {
// Handle internally
reply.clear();
if ( serverURLStr.find("/TMap/") != MC2String::npos ) {
MC2String urlParam = STLStringUtility::basename( url2.getFile() );
if ( !urlParam.empty() ) {
DataBuffer* d = m_thread->getTileMap( urlParam.c_str() );
if ( d != NULL ) {
ures = 200;
reply.append( reinterpret_cast<char*>( d->getBufferAddress() ),
d->getCurrentOffset() );
outHeaders.setStartLine( 200 );
} else {
outHeaders.setStartLine( 503 );
}
delete d;
}
}
} else {
// Send request using the parserthreads urlfetcher
URLFetcher* f = m_thread->getURLFetcher();
HttpHeader sendHeaders; // Extra headers to send
// TODO: Add byterange using fromByte and toByte if not 0,MAX_UINT32
// so we don't download whole file all the time.
MC2String peerIPstr = NetUtility::ip2str( peerIP );
sendHeaders.addHeaderLine( "X-Forwarded-For", peerIPstr );
static const MC2String notForwardHeadersStr[] = {
"X-WAYF-CT",
HttpHeaderLines::CONTENT_TYPE,
HttpHeaderLines::CONTENT_LENGTH,
HttpHeaderLines::CONNECTION,
HttpHeaderLines::TRANSFER_ENCODING,
HttpHeaderLines::X_FORWARDED_FOR,
HttpHeaderLines::PROXY_CONNECTION,
HttpHeaderLines::HOST,
HttpHeaderLines::TE,
HttpHeaderLines::TRAILER,
HttpHeaderLines::KEEP_ALIVE,
HttpHeaderLines::PROXY_AUTHENTICATE,
HttpHeaderLines::PROXY_AUTHORIZATION,
HttpHeaderLines::UPGRADE,
};
// TODO: Also remove all headers in Connection: header. Like
// "Connection: Keep-Alive, Trailer" should delete those two.
static const set< MC2String, strNoCaseCompareLess > notForwardHeaders(
BEGIN_ARRAY( notForwardHeadersStr ),
END_ARRAY( notForwardHeadersStr ) );
if ( inHeaders != NULL ) {
const HttpHeader::HeaderMap& headers = inHeaders->getHeaderMap();
//.........这里部分代码省略.........