Helper methods for HTTP request/response handling

package ArangoDBClient
since 0.2

 Methods

Create a request string (header and body)

buildRequest(\ArangoDBClient\ConnectionOptions $options, string $connectionHeader, string $method, string $url, string $body, array $customHeaders = array()) : string
Static

Parameters

$options

\ArangoDBClient\ConnectionOptions
  • connection options

$connectionHeader

string
  • pre-assembled header string for connection

$method

string
  • HTTP method

$url

string
  • HTTP URL

$body

string
  • optional body to post

$customHeaders

array
  • any array containing header elements

Exceptions

\ArangoDBClient\ClientException

Returns

string- assembled HTTP request string

Create a one-time HTTP connection by opening a socket to the server

createConnection(\ArangoDBClient\ConnectionOptions $options) : resource
Static

It is the caller's responsibility to close the socket

Parameters

$options

\ArangoDBClient\ConnectionOptions
  • connection options

Exceptions

\ArangoDBClient\ConnectException

Returns

resource- socket with server connection, will throw when no connection can be established

Process a string of HTTP headers into an array of header => values.

parseHeaders(string $headers) : array
Static

Parameters

$headers

string
  • the headers string

Returns

array

Splits an http message into its header and body.

parseHttpMessage(string $httpMessage, string $originUrl = null, string $originMethod = null) : array
Static

Parameters

$httpMessage

string

The http message string.

$originUrl

string

The original URL the response is coming from

$originMethod

string

The HTTP method that was used when sending data to the origin URL

Exceptions

\ArangoDBClient\ClientException

Returns

array

Execute an HTTP request on an opened socket

transfer(resource $socket, string $request, string $method) : string
Static

It is the caller's responsibility to close the socket

Parameters

$socket

resource
  • connection socket (must be open)

$request

string
  • complete HTTP request as a string

$method

string
  • HTTP method used (e.g. "HEAD")

Exceptions

\ArangoDBClient\ClientException

Returns

string- HTTP response string as provided by the server

Validate an HTTP request method name

validateMethod(string $method) : boolean
Static

Parameters

$method

string
  • method name

Exceptions

\ArangoDBClient\ClientException

Returns

boolean- always true, will throw if an invalid method name is supplied

 Constants

 

HTTP Header for making an operation asynchronous

ASYNC_HEADER = 'X-Arango-Async' 
 

Chunk size (number of bytes processed in one batch)

CHUNK_SIZE = 8192 
 

End of line mark used in HTTP

EOL = "\r\n" 
 

HTTP DELETE string constant

METHOD_DELETE = 'DELETE' 
 

HTTP GET string constant

METHOD_GET = 'GET' 
 

HTTP HEAD string constant

METHOD_HEAD = 'HEAD' 
 

HTTP PATCH string constant

METHOD_PATCH = 'PATCH' 
 

HTTP POST string constant

METHOD_POST = 'POST' 
 

HTTP PUT string constant

METHOD_PUT = 'PUT' 
 

Boundary string for batch request parts

MIME_BOUNDARY = 'XXXsubpartXXX' 
 

HTTP protocol version used, hard-coded to version 1.1

PROTOCOL = 'HTTP/1.1' 
 

Separator between header and body

SEPARATOR = "\r\n\r\n"