MCPcopy Create free account
hub / github.com/apache/trafficserver / host_set

Method host_set

plugins/experimental/txn_box/plugin/src/ts_util.cc:492–521  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

490}
491
492bool
493ts::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
523bool
524ts::HttpRequest::port_set(in_port_t port)

Callers 3

invokeMethod · 0.45
URL_Loc_SetFunction · 0.45
Req_Loc_SetFunction · 0.45

Calls 11

urlMethod · 0.95
fieldMethod · 0.80
emptyMethod · 0.45
hostMethod · 0.45
is_validMethod · 0.45
valueMethod · 0.45
sizeMethod · 0.45
printMethod · 0.45
assignMethod · 0.45
viewMethod · 0.45
field_createMethod · 0.45

Tested by

no test coverage detected