| 320 | // ---------------------------------------------------------------------------------------- |
| 321 | |
| 322 | void write_http_response ( |
| 323 | std::ostream& out, |
| 324 | outgoing_things outgoing, |
| 325 | const std::string& result |
| 326 | ) |
| 327 | { |
| 328 | using namespace http_impl; |
| 329 | key_value_map& new_cookies = outgoing.cookies; |
| 330 | key_value_map_ci& response_headers = outgoing.headers; |
| 331 | |
| 332 | // only send this header if the user hasn't told us to send another kind |
| 333 | bool has_content_type = false, has_location = false; |
| 334 | for(key_value_map_ci::const_iterator ci = response_headers.begin(); ci != response_headers.end(); ++ci ) |
| 335 | { |
| 336 | if ( !has_content_type && strings_equal_ignore_case(ci->first , "content-type") ) |
| 337 | { |
| 338 | has_content_type = true; |
| 339 | } |
| 340 | else if ( !has_location && strings_equal_ignore_case(ci->first , "location") ) |
| 341 | { |
| 342 | has_location = true; |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | if ( has_location ) |
| 347 | { |
| 348 | outgoing.http_return = 302; |
| 349 | } |
| 350 | |
| 351 | if ( !has_content_type ) |
| 352 | { |
| 353 | response_headers["Content-Type"] = "text/html"; |
| 354 | } |
| 355 | |
| 356 | response_headers["Content-Length"] = cast_to_string(result.size()); |
| 357 | |
| 358 | out << "HTTP/1.0 " << outgoing.http_return << " " << outgoing.http_return_status << "\r\n"; |
| 359 | |
| 360 | // Set any new headers |
| 361 | for(key_value_map_ci::const_iterator ci = response_headers.begin(); ci != response_headers.end(); ++ci ) |
| 362 | { |
| 363 | out << ci->first << ": " << ci->second << "\r\n"; |
| 364 | } |
| 365 | |
| 366 | // set any cookies |
| 367 | for(key_value_map::const_iterator ci = new_cookies.begin(); ci != new_cookies.end(); ++ci ) |
| 368 | { |
| 369 | out << "Set-Cookie: " << urlencode(ci->first) << '=' << urlencode(ci->second) << "\r\n"; |
| 370 | } |
| 371 | out << "\r\n" << result; |
| 372 | } |
| 373 | |
| 374 | // ---------------------------------------------------------------------------------------- |
| 375 |
no test coverage detected