Skip to content

feat: Response header access, settable timeouts, strict typing - #4

Open
joramkruijer wants to merge 4 commits into
masterfrom
response-headers-timeout
Open

joramkruijer wants to merge 4 commits into
masterfrom
response-headers-timeout

Conversation

@joramkruijer

Copy link
Copy Markdown
Contributor

NoREST now requires php >= 8.1, which enabled the adding of strict typing.

This merge also introduces a quite a few changes and improvements:

  • Response headers are now accessible via $client->getLastResponseHeaders(), and in the exceptions by calling getResponseHeaders() on the caught exception
  • Timeouts for request duration can now be set via $client->setTimeout(60), or directly when constructing a new client: new Client(...)->setTimeout(60). To set a different TLS handshake timeout as well: $client->setTimeout(60, 10). The default timeouts are 30s for the overall request, and 10s for TLS handshakes.
  • Unknown content-type in a response will no longer throw an InvalidArgumentException: instead the body is returned as-is, without any decoding being attempted
  • Passing invalid request payloads (such as an array with content-type set to text/plain, or a non-array/object payload with content-type application/x-www-form-urlencoded will throw an InvalidArgumentException
  • String request payloads are not content-type-encoded: a string passed to post() / put() / patch() is sent as-is regardless of content type. We assume the caller has already encoded strings passed to these functions: simply pass an array or object to have it encoded automatically.
  • Content-type is now always guaranteed on the client, even if when constructing NoREST with [] or a headers array that omits it entirely

For development:

  • CI code checking has been added, with phpstan (level 9) and phpcs (PSR-12) verified on PHP 8.1 and 8.5. This merge therefore adds dev-dependencies phpstan/phpstan, squizlabs/php_codesniffer and their respective config files.

@joramkruijer joramkruijer self-assigned this Sep 23, 2026
@joramkruijer joramkruijer added the enhancement New feature or request label Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant