forked from ravinet/mahimahi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp_request.cc
44 lines (35 loc) · 1.26 KB
/
http_request.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* -*-mode:c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
#include "http_request.hh"
#include "exception.hh"
#include "ezio.hh"
using namespace std;
void HTTPRequest::calculate_expected_body_size( void )
{
assert( state_ == BODY_PENDING );
if ( first_line_.substr( 0, 4 ) == "GET "
or first_line_.substr( 0, 5 ) == "HEAD " ) {
set_expected_body_size( true, 0 );
} else if ( first_line_.substr( 0, 5 ) == "POST " ) {
if ( !has_header( "Content-Length" ) ) {
throw Exception( "HTTPRequest", "does not support chunked requests" );
}
set_expected_body_size( true, myatoi( get_header_value( "Content-Length" ) ) );
} else {
throw Exception( "Cannot handle HTTP method", first_line_ );
}
}
size_t HTTPRequest::read_in_complex_body( const std::string & )
{
/* we don't support complex bodies */
throw Exception( "HTTPRequest", "does not support chunked requests" );
}
bool HTTPRequest::eof_in_body( void ) const
{
throw Exception( "HTTPRequest", "got EOF in middle of body" );
}
bool HTTPRequest::is_head( void ) const
{
assert( state_ > FIRST_LINE_PENDING );
/* RFC 2616 5.1.1 says "The method is case-sensitive." */
return first_line_.substr( 0, 5 ) == "HEAD ";
}