Radius::HTTPClient
module. It provides common
configuration to specify HTTP backend servers, HTTP request methods,
content encoding, TLS parameters and failure behaviour. HTTP connection
establishment and response processing are done asynchronously. This allows
non-blocking communication even with slow backends.
Radius::HTTPClient
module is built on top of Radiator
Stream module and provides configuration similar to other stream
configuration clauses such as RadSec.Radius::HTTPClient
:HTTP::Client
configuration clauses
support stream
TLS parameters.URL
parameters
are supported. At least one URL
must be defined.
Optional comma separated priority value may follow an URL. If priority is
not defined, it defaults to 1. When URL is configured to use
https
scheme, TLS client parameters must be configured.
For more information, see Section 3.11. TLS configuration# Service is reachable from two local ports URL http://127.0.0.1:8888/radius URL http://127.0.0.1:8889/radius # Use port 443 and non-default priority URL https://api.example.com/radius, 2 URL https://api.example.net/radius, 3Radiator's special formatting characters, see Section 3.3. Special formatters, in
URL
are processed only when
FormatURL
is set. The supported formatters are
documented for each clause that uses HTTP client parameters. See AuthBy
REST
for an example.AuthBy
REST
for an example.GET
, DELETE
, POST
,
PUT
or PATCH
. Defaults to
GET
.# The service we use requires POST RequestMethod POST
POST
, PUT
and
PATCH
request methods. One of:application/json
application/x-www-form-urlencoded
text/plain
application/text
application/plain
keyword=value
encoding without escaping is used. Defaults
to application/x-www-form-urlencoded
# The service we use requires POSTs in JSON format RequestContentType application/json
RequestHeader
parameters. Format is header name, with
an optional ':', followed by space and the header value. Defaults to not
set.# Add our custom HTTP header RequestHeader User-Agent Radiator/4.xx AuthBy REST
Basic
. Defaults to
not set. When HTTP_AuthenticationHook
is configured, HTTP_AuthenticationScheme
is
ignored.# API access requires HTTP authentication HTTP_AuthenticationScheme Basic HTTP_Username mikem HTTP_Password fred
HTTP_AuthenticationHook
is configured,
HTTP_AuthenticationScheme
is ignored. The hook is
passed the following arguments:Radius::HTTPClient
derived clauseHTTP::Request
class
representing the API request being currently built# API access requires HTTP authentication HTTP_AuthenticationHook file:"%D/http-auth-hook.pl" HTTP_Username mikem HTTP_Password fred
HTTP_AuthenticationScheme
is
configured. This parameter may also be accessed by hook configured with
HTTP_AuthenticationHook
. See HTTP_AuthenticationScheme
for an example.HTTP_AuthenticationScheme
is
configured. This parameter may also be accessed by hook configured with
HTTP_AuthenticationHook
. See HTTP_AuthenticationScheme
for an example.1.0
and 1.1
.
Defaults to 1.1
.# API access requires HTTP/1.0 HTTP_Version 1.0
# Time related values are in seconds. NoreplyTimeout 5 FailureBackoffTime 60 MaxFailedRequests 3 MaxFailedGraceTime 10
MaxFailedRequests
consecutive failures. Backend failure occurs when a backend does not
respond or HTTP response status code indicates a failure. Defaults to not
set. See NoreplyTimeout
for an example.FailureBackoffTime
is triggered.
Defaults to not set. See NoreplyTimeout
for an example.MaxFailedGraceTime
specifes the time
period (in seconds) over which MaxFailedRequests
failures will cause the backend to be be assumed to be failed. Defaults to
not set. The default value lets the HTTP client to choose a reasonable
value which is typically very large. Very short values require a high
number of failures to set target host as failed. This value should only be
changed in special cases.# Backend allows only a small number of connections Connections 1 MaxConnections 10
Connections
for an example.# Do some pre-processing before passing response to upper layers. MapResponseHook file:"%D/http-map-response-hook.pl"
AuthBy
REST
.# Replace an array reference with the array's first member # Received JSON: [ { "a1": 1 }, { "b2": 2 }] # AuthBy REST needs just the first object, the one with key "a1" <AuthBy REST> # Parameters, location within AuthBy does not matter MapResponseHook sub { $_[0]->{server_response} = $_[0]->{server_response}->[0]; } # More parameters </AuthBy>
LocalPort
is a string, it can be a port
number or name. It binds the local port if
LocalAddress
is defined. If
LocalPort
is not specified or if it is set to
0
, a port number is allocated in the usual
way.LocalAddress
must be either IPv4 or IPv6
addresses.LocalAddress 203.63.154.29 LocalPort 12345
Trace
level 5 EXTRA_DEBUG
. The
example below shows how to enable HTTP request and response logging with
Trace
level 5.# Enable global extra debugging Trace 5 # AuthBy REST is a HTTP::Client <AuthBy REST> Debug # Other paramters </AuthBy>