本文整理汇总了C++中HTTPResponse::SetStatusLine方法的典型用法代码示例。如果您正苦于以下问题:C++ HTTPResponse::SetStatusLine方法的具体用法?C++ HTTPResponse::SetStatusLine怎么用?C++ HTTPResponse::SetStatusLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTPResponse
的用法示例。
在下文中一共展示了HTTPResponse::SetStatusLine方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handle_request
//.........这里部分代码省略.........
// Make a BDataIO wrapper for the in and out pipes
DesIO pipeIO( inDes, outDes );
// If the request contains a content body, feed it into stdin of the CGI script
if( pb->request->GetContentLength() > 0 )
pb->request->SendBody( &pipeIO );
// Buffer the response body for better performance
response.SetBodyBuffering( true );
// Read first line to detect use of Non-Parsed Header Output
io_getline( &pipeIO, headBuffer, fieldSize );
// Strip the '\r' character if there is one
int32 size;
size = strlen( headBuffer )-1;
if( headBuffer[size] == '\r' )
headBuffer[size] = 0;
// Is NPH Output?
if( strncmp( "HTTP/", headBuffer, 5 ) == 0 )
{
DataIOPump ioPump;
BufferedIO bufio( pb->request->GetReplyIO() );
bufio.DoAllocate();
io_printf( &bufio, "%s\r\n", headBuffer );
ioPump.StartPump( &pipeIO, &bufio, contentLength );
bufio.Flush();
persistant = false;
}
else // using Parsed Header Output
{
// Add Date header
time_t now;
struct tm *brokentime;
now = time( NULL );
brTimeLock.Lock();
brokentime = gmtime( &now );
strftime (fieldValue, 256, kHTTP_DATE, brokentime);
brTimeLock.Unlock();
response.AddHeader( kHEAD_DATE, fieldValue );
// Add line used to detect NPH as CGI header
response.AddHeader( headBuffer );
// Receive the CGI headers
response.ReceiveHeaders( &pipeIO );
// If Location header, don't expect any more headers
if( (sPtr = response.FindHeader( "Location", fieldValue, fieldSize )) )
{
response.SetStatusLine( 302 ); // 302 Moved Temporarily
}
else
{
if( (sPtr = response.FindHeader( "Status", fieldValue, fieldSize )) )
{
response.RemoveHeader( (char *)sPtr ); // Don't forward to client
response.SetStatusLine( fieldValue );
}
else
response.SetStatusLine( 200 );
}
// Don't cache the response
if( !response.FindHeader( "Cache-Control", fieldValue, fieldSize ) )
response.AddHeader( "Cache-Control: no-cache" );
if( !response.FindHeader( "Pragma", fieldValue, fieldSize ) )
response.AddHeader( "Pragma: no-cache" );
// Content-Length header?
int32 contentLength = 0;
if( (sPtr = response.FindHeader( kHEAD_LENGTH, fieldValue, fieldSize )) )
{
contentLength = strtol( fieldValue, (char **)&headBuffer, 10 );
response.SetContentLength( contentLength );
}
else // No content-length provided; close connection on return
{
response.AddHeader( "Connection: close" );
persistant = false;
}
pb->Logprintf( "%ld Status-Line: %s\n", pb->sn, response.GetStatusLine() );
if( pb->request->GetMethod() != METHOD_HEAD )
response.SetMessageBody( &pipeIO );
pb->request->SendReply( &response );
}
// Close remaining ends of pipes
close( ipipe[0] );
close( opipe[1] );
pb->closeConnection = !persistant;
return B_OK;
}