final class HttpTransport implements TransportInterface (View source)

Low-level HTTP transport over cURL.

Owns the cURL handle lifecycle and exposes a single post() method.

Constants

PROTECTED_OPTIONS

cURL options this transport owns; a caller may not override them through the per-call option bag ({AbstractClient::setExtraCurlOptions()}).

Passing one of these to {\CNIC\post()} raises {\CNIC\Exception\UnsupportedFeatureException} rather than being silently dropped.

Two kinds of option, protected for two different reasons:

  • Request-envelope invariants — CURLOPT_URL, POST, POSTFIELDS, RETURNTRANSFER, HEADER. Response parsing is written against exactly this envelope; CURLOPT_RETURNTRANSFER => 0, for instance, makes curl_exec() return true and leaves the parser with nothing to read.
  • TLS verification posture — CURLOPT_SSL_VERIFYPEER, SSL_VERIFYHOST. Turning certificate verification off is a deliberate, security-relevant act and must not be reachable through a generic convenience bag.

Everything else the transport sets (CURLOPT_TIMEOUT, CONNECTTIMEOUT, USERAGENT) is a default the caller may override. CURLOPT_HTTPHEADER is the one middle case: callers may add header lines but not restate the transport's own — see {\CNIC\appendHeaders()}.

Keyed by the cURL constant, valued with its name, so the rejection message can name what the caller passed instead of handing back a bare integer to look up. One list, not two: a second list of the same constants could drift out of step with this one.

Keep the list exactly the envelope and TLS keys — widening it silently re-breaks legitimate tuning, narrowing it gives away one of the two guarantees. Pinned by HttpTransportCurlOptionsTest::testProtectedOptionsAreExactlyTheEnvelopeAndTlsKeys().

Methods

array
post(string $url, string $data, int $timeoutSeconds, string $userAgent, array $options = [])

Execute a POST request and return the raw response.

void
close()

Close and reset the cURL handle.

Details

array post(string $url, string $data, int $timeoutSeconds, string $userAgent, array $options = [])

Execute a POST request and return the raw response.

The caller's $options win over the transport's own defaults on key collision, except for {\CNIC\PROTECTED_OPTIONS}, which are rejected. CURLOPT_HTTPHEADER is additive: caller lines are appended to the transport's, and restating one of the transport's own headers is rejected rather than allowed to override it (see {\CNIC\appendHeaders()}).

Parameters

string $url
string $data

serialized POST payload

int $timeoutSeconds

0 carries cURL's meaning — no timeout

string $userAgent
array $options

additional cURL options, overriding the implementation's defaults

Return Value

array

[rawResponse, errorMessage|null]

Exceptions

UnsupportedFeatureException

void close()

Close and reset the cURL handle.

Return Value

void