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

Function URL_Loc_Set

plugins/experimental/txn_box/plugin/src/Machinery.cc:353–382  ·  view source on GitHub ↗

Set the location in a URL, accepting either a string or a tuple of .

Source from the content-addressed store, hash-verified

351
352/// Set the location in a URL, accepting either a string or a tuple of <host, port>.
353void
354URL_Loc_Set(Context &ctx, Expr &expr, ts::URL &url)
355{
356 auto value = ctx.extract(expr);
357 TextView host_token;
358 int port = -1; // if still -1 after parsing, the parsing failed.
359 if (auto loc = std::get_if<IndexFor(STRING)>(&value); nullptr != loc) {
360 // split the string to get the pieces.
361 Loc_String_Parse(*loc, host_token, port);
362 } else if (auto t = std::get_if<IndexFor(TUPLE)>(&value); nullptr != t) {
363 // Must be host name, then port.
364 if (t->size() > 0) {
365 if (auto &f0 = (*t)[0]; f0.index() == IndexFor(STRING)) {
366 host_token = std::get<IndexFor(STRING)>(f0);
367 if (t->size() > 1) {
368 auto &f1 = (*t)[1];
369 if (is_empty(f1)) {
370 port = 0; // clear port.
371 } else {
372 port = f1.as_integer(-1); // try as integer, fail if not convertible.
373 }
374 }
375 }
376 }
377 }
378 if (0 <= port && port < std::numeric_limits<in_port_t>::max()) {
379 url.host_set(host_token);
380 url.port_set(port); // if @a port is 0 then it will be removed from the URL.
381 }
382}
383
384/// Set the location in the Host field and URL (if needed).
385void

Callers 1

invokeMethod · 0.85

Calls 9

Loc_String_ParseFunction · 0.85
IndexForFunction · 0.85
indexMethod · 0.80
as_integerMethod · 0.80
is_emptyFunction · 0.50
extractMethod · 0.45
sizeMethod · 0.45
host_setMethod · 0.45
port_setMethod · 0.45

Tested by

no test coverage detected