| 273 | } |
| 274 | |
| 275 | std::string Http::Request::prepare( const Http& http ) const { |
| 276 | std::ostringstream out; |
| 277 | |
| 278 | // Convert the method to its string representation |
| 279 | std::string method = methodToString( mMethod ); |
| 280 | |
| 281 | // Write the first line containing the request type |
| 282 | if ( http.getProxy().empty() ) { |
| 283 | out << method << " " << mUri << " "; |
| 284 | } else { |
| 285 | URI uri = http.getURI(); |
| 286 | uri.setPathEtc( mUri ); |
| 287 | out << method << " " << uri.toString() << " "; |
| 288 | } |
| 289 | |
| 290 | out << "HTTP/" << mMajorVersion << "." << mMinorVersion << "\r\n"; |
| 291 | |
| 292 | // Write fields |
| 293 | for ( FieldTable::const_iterator i = mFields.begin(); i != mFields.end(); ++i ) { |
| 294 | out << i->first << ": " << i->second << "\r\n"; |
| 295 | } |
| 296 | |
| 297 | // Use an extra \r\n to separate the header from the body |
| 298 | out << "\r\n"; |
| 299 | |
| 300 | // Add the body |
| 301 | out << mBody; |
| 302 | |
| 303 | return out.str(); |
| 304 | } |
| 305 | |
| 306 | bool Http::Request::hasField( const std::string& field ) const { |
| 307 | return mFields.find( String::toLower( field ) ) != mFields.end(); |
no test coverage detected