| 490 | } |
| 491 | |
| 492 | bool |
| 493 | ts::HttpRequest::host_set(swoc::TextView const &host) |
| 494 | { |
| 495 | auto url{this->url()}; |
| 496 | bool force_host_p = true; |
| 497 | if (!url.host().empty()) { |
| 498 | url.host_set(host); |
| 499 | force_host_p = false; |
| 500 | } |
| 501 | auto field{this->field(HTTP_FIELD_HOST)}; |
| 502 | if (field.is_valid()) { |
| 503 | auto text = field.value(); |
| 504 | TextView host_token, port_token; |
| 505 | if (swoc::IPEndpoint::tokenize(text, &host_token, &port_token)) { |
| 506 | size_t n = host.size() + 1 + port_token.size(); |
| 507 | swoc::FixedBufferWriter w{static_cast<char *>(alloca(n)), n}; |
| 508 | if (port_token.size()) { |
| 509 | w.print("{}:{}", host, port_token); |
| 510 | } else { |
| 511 | w.print("{}", host); |
| 512 | } |
| 513 | field.assign(w.view()); |
| 514 | } else { // It's messed up, do the best we can by setting it to a valid value. |
| 515 | field.assign(host); |
| 516 | } |
| 517 | } else if (force_host_p) { |
| 518 | this->field_create(HTTP_FIELD_HOST).assign(host); |
| 519 | } |
| 520 | return true; |
| 521 | } |
| 522 | |
| 523 | bool |
| 524 | ts::HttpRequest::port_set(in_port_t port) |