Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,9 @@ Get the origin server address for transaction :arg:`txnp`.
The pointer is valid only for the current callback. Clients that
need to keep the value across callbacks must maintain their own
storage.

See Also
========

:manpage:`TSAPI(3ts)`,
:manpage:`TSHttpTxnServerAddrSet(3ts)`
32 changes: 28 additions & 4 deletions doc/developer-guide/api/functions/TSHttpTxnServerAddrSet.en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,32 @@ Set the origin server address for transaction :arg:`txnp`. This includes the por
The address family is also set by the contents of :arg:`addr`. The address data is copied out of
:arg:`addr` so there is no dependency on the lifetime of that object.

This hook must be called no later than TS_HTTP_OS_DNS_HOOK. If this is called then DNS resolution
will not be done as the address of the server is already know.
This hook must be called no later than TS_HTTP_OS_DNS_HOOK. If this
is called prior to TS_HTTP_OS_DNS_HOOK, DNS resolution will not be
done as the address of the server is already known.

An error value is returned if :arg:`addr` does not contain a valid IPv4 or IPv6 address with a valid
(non-zero) port.
Return Value
============

:data:`TS_ERROR` is returned if :arg:`addr` does not contain a valid
IPv4 or IPv6 address with a valid (non-zero) port.

Notes
=====

If |TS| is configured to retry connections to origin servers and
:func:`TSHttpTxnServerAddrGet` has been called, |TS| will return
to TS_HTTP_OS_DNS_HOOK so to let the plugin set a different server
address. Plugins should be prepared for TS_HTTP_OS_DNS_HOOK and any
subsequent hooks to be called multiple times.

Once a plugin calls :func:`TSHttpTxnServerAddrGet` any prior DNS
resolution results are lost. The plugin should use
:func:`TSHttpTxnServerAddrGet` to preserve any DNS Results that
might need.

See Also
========

:manpage:`TSAPI(3ts)`,
:manpage:`TSHttpTxnServerAddrGet(3ts)`
10 changes: 10 additions & 0 deletions proxy/http/HttpTransact.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3771,6 +3771,16 @@ HttpTransact::handle_response_from_server(State *s)
retry_server_connection_not_open(s, s->current.state, max_connect_retries);
DebugTxn("http_trans", "[handle_response_from_server] Error. Retrying...");
s->next_action = how_to_open_connection(s);

if (s->api_server_addr_set) {
// If the plugin set a server address, back up to the OS_DNS hook
// to let it try another one. Force OS_ADDR_USE_CLIENT so that
// in OSDNSLoopkup, we back up to how_to_open_connections which
// will tell HttpSM to connect the origin server.

s->dns_info.os_addr_style = DNSLookupInfo::OS_ADDR_USE_CLIENT;
TRANSACT_RETURN(SM_ACTION_API_OS_DNS, OSDNSLookup);
}
return;
}
} else {
Expand Down