VuFindHttp API Documentation

HttpService
in package
implements HttpServiceInterface

VuFind HTTP service.

Tags
category

VuFind

author

David Maus maus@hab.de

license

http://opensource.org/licenses/gpl-2.0.php GNU General Public License

link
https://vufind.org/wiki/development

Interfaces, Classes, Traits and Enums

HttpServiceInterface
VuFind HTTP service interface definition.

Table of Contents

LOCAL_ADDRESS_RE  = '@^(localhost|127(\\.\\d+){3}|\\[::1\\])@'
Default regular expression matching a request to localhost.
$defaultAdapter  : AdapterInterface
Default adapter
$defaults  : array<string|int, mixed>
Default client options.
$localAddressesRegEx  : string
Regular expression matching a request to localhost or hosts that are not proxied.
$proxyConfig  : array<string|int, mixed>
Proxy configuration.
__construct()  : void
Constructor.
createClient()  : Client
Return a new HTTP client.
get()  : Response
Perform a GET request.
isAssocParams()  : bool
Return TRUE if argument is an associative array.
post()  : Response
Perform a POST request.
postForm()  : Response
Post form data.
proxify()  : Client
Proxify an existing client.
setDefaultAdapter()  : void
Set a default HTTP adapter (primarily for testing purposes).
createQueryString()  : string
Return query string based on params.
hasCurlAdapterAsDefault()  : bool
Are we configured to use the CURL adapter?
isLocal()  : bool
Return TRUE if argument refers to localhost.
send()  : Response
Send HTTP request and return response.
setCurlProxyOptions()  : void
Set proxy options in a Curl adapter.

Constants

LOCAL_ADDRESS_RE

Default regular expression matching a request to localhost.

public string LOCAL_ADDRESS_RE = '@^(localhost|127(\\.\\d+){3}|\\[::1\\])@'

Properties

$defaultAdapter

Default adapter

protected AdapterInterface $defaultAdapter = null

$defaults

Default client options.

protected array<string|int, mixed> $defaults

$localAddressesRegEx

Regular expression matching a request to localhost or hosts that are not proxied.

protected string $localAddressesRegEx = self::LOCAL_ADDRESS_RE
Tags
see
Proxy::$config

$proxyConfig

Proxy configuration.

protected array<string|int, mixed> $proxyConfig
Tags
see
Proxy::$config

Methods

__construct()

Constructor.

public __construct([array<string|int, mixed> $proxyConfig = [] ][, array<string|int, mixed> $defaults = [] ][, array<string|int, mixed> $config = [] ]) : void
Parameters
$proxyConfig : array<string|int, mixed> = []

Proxy configuration

$defaults : array<string|int, mixed> = []

Default HTTP options

$config : array<string|int, mixed> = []

Other configuration

Return values
void

createClient()

Return a new HTTP client.

public createClient([string $url = null ][, string $method = LaminasHttpRequest::METHOD_GET ][, float $timeout = null ]) : Client
Parameters
$url : string = null

Target URL

$method : string = LaminasHttpRequest::METHOD_GET

Request method

$timeout : float = null

Request timeout in seconds

Return values
Client

get()

Perform a GET request.

public get(string $url[, array<string|int, mixed> $params = [] ][, float $timeout = null ][, array<string|int, mixed> $headers = [] ]) : Response
Parameters
$url : string

Request URL

$params : array<string|int, mixed> = []

Request parameters

$timeout : float = null

Request timeout in seconds

$headers : array<string|int, mixed> = []

Request headers

Return values
Response

isAssocParams()

Return TRUE if argument is an associative array.

public static isAssocParams(array<string|int, mixed> $array) : bool
Parameters
$array : array<string|int, mixed>

Array to test

Return values
bool

post()

Perform a POST request.

public post(string $url[, mixed $body = null ][, string $type = 'application/octet-stream' ][, float $timeout = null ][, array<string|int, mixed> $headers = [] ]) : Response
Parameters
$url : string

Request URL

$body : mixed = null

Request body document

$type : string = 'application/octet-stream'

Request body content type

$timeout : float = null

Request timeout in seconds

$headers : array<string|int, mixed> = []

Request http-headers

Return values
Response

postForm()

Post form data.

public postForm(string $url[, array<string|int, mixed> $params = [] ][, float $timeout = null ]) : Response
Parameters
$url : string

Request URL

$params : array<string|int, mixed> = []

Form data

$timeout : float = null

Request timeout in seconds

Return values
Response

proxify()

Proxify an existing client.

public proxify(Client $client[, array<string|int, mixed> $options = [] ]) : Client

Returns the client given as argument with appropriate proxy setup.

Parameters
$client : Client

HTTP client

$options : array<string|int, mixed> = []

Laminas ProxyAdapter options

Return values
Client

setDefaultAdapter()

Set a default HTTP adapter (primarily for testing purposes).

public setDefaultAdapter(AdapterInterface $adapter) : void
Parameters
$adapter : AdapterInterface

Adapter

Return values
void

createQueryString()

Return query string based on params.

protected createQueryString([array<string|int, mixed> $params = [] ]) : string
Parameters
$params : array<string|int, mixed> = []

Parameters

Return values
string

hasCurlAdapterAsDefault()

Are we configured to use the CURL adapter?

protected hasCurlAdapterAsDefault() : bool
Return values
bool

isLocal()

Return TRUE if argument refers to localhost.

protected isLocal(string $host) : bool
Parameters
$host : string

Host to check

Return values
bool

send()

Send HTTP request and return response.

protected send(Client $client) : Response
Parameters
$client : Client

HTTP client to use

Tags
throws
RuntimeException
todo

Catch more exceptions, maybe?

Return values
Response

setCurlProxyOptions()

Set proxy options in a Curl adapter.

protected setCurlProxyOptions(Curl $adapter) : void
Parameters
$adapter : Curl

Adapter to configure

Return values
void

Search results