Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected / Cached Result from "getRequestHeader" #90

Closed
toitzi opened this issue Jul 18, 2019 · 3 comments
Closed

Unexpected / Cached Result from "getRequestHeader" #90

toitzi opened this issue Jul 18, 2019 · 3 comments

Comments

@toitzi
Copy link

toitzi commented Jul 18, 2019

Noticed this while i wanted to unittest my application with PHPUnit:

Let's assume you have the following code:

<?php

    // Unset $_SERVER for testing
    unset($_SERVER);

    // Set custom $_SERVER variables
    $_SERVER = ['HTTP_WEIRD_HTTP_HEADER' => 'First value'];

    // Read Header with pecl_http
    $header = \http\Env::getRequestHeader();

    // Dump result - THIS ONE IS CORRECT
    var_dump($header);

    // Unset $_SERVER again (you could also just overwrite the old one instead)
    unset($_SERVER);

    // Change/Re-Add a new HTTP Header
    $_SERVER = ['HTTP_WEIRD_HTTP_HEADER' => 'Second value'];

    // Read header again with pecl_http
    $header = \http\Env::getRequestHeader();

    // Dump result - THIS ONE IS FALSE
    var_dump($header);

?>

Error Description:

As stated in the code comments, the first var_dump returns the correct result ("First value"). The second one does not (It also returns "First value").

Expected behavior:

Second var_dump should return "Second value"

Are the results cached or something like that?

p.s it doesn't matter which HTTP Headers you change / add / remove it will always return the first result

@toitzi toitzi closed this as completed Jul 18, 2019
@toitzi toitzi reopened this Jul 18, 2019
@m6w6
Copy link
Owner

m6w6 commented Jul 18, 2019

Yeah, you're right, they are cached after first access. :-/

@toitzi
Copy link
Author

toitzi commented Jul 18, 2019

Is there any option to "invaldiate" caches? Is this expected behavior?

@m6w6
Copy link
Owner

m6w6 commented Jul 18, 2019

Yes, that is intentional, and unfortunately, there's no switch yet to invalidate the caches.

m6w6 added a commit that referenced this issue Aug 4, 2021
m6w6 added a commit that referenced this issue Aug 30, 2021
m6w6 added a commit that referenced this issue Aug 30, 2021
m6w6 added a commit that referenced this issue Aug 30, 2021
* Fixed PHP-8.1 compatibility (see gh issues #114, #115 and #118)
* Fixed cookies failing with libcurl >= 7.77 (see gh issue #116)
* Fixed tests using $_ENV instead of getenv() to find executables in PATH (see gh issue #113)
* Added http\Env::reset(): resets internal HTTP request cache (see gh issue #90)
m6w6 added a commit that referenced this issue Aug 30, 2021
* Fixed PHP-8.1 compatibility (see gh issues #114, #115 and #118)
* Fixed cookies failing with libcurl >= 7.77 (see gh issue #116)
* Fixed tests using $_ENV instead of getenv() to find executables in PATH (see gh issue #113)
* Added http\Env::reset(): resets internal HTTP request cache (see gh issue #90)
@m6w6 m6w6 closed this as completed Sep 7, 2021
m6w6 added a commit that referenced this issue Jun 10, 2022
* Fix http\Client::requeue() not updating response callback
* Backport bug fixes and features from v4:
  * Fixed configure reliably finding the right libcurl features available
  * Fixed cookie handling with libcurl 7.77+ and consistently across all
    supported libcurl versions (follow-up to gh issue #116)
  * Fixed cookies failing with libcurl >= 7.77 (see gh issue #116)
  * Fixed tests using $_ENV instead of getenv() to find executables in PATH (see gh issue #113)
  * Fixed configure on systems which do not provide icu-config
  * Fixed gh-issue #89: Cookie handling cannot be disabled since v3.2.1
  * Added http\Env::reset(): resets internal HTTP request cache (see gh issue #90)
  * Added request options:
    * http\Client\Curl::$abstract_unix_socket
    * http\Client\Curl::$altsvc
    * http\Client\Curl::$altsvc_ctrl
    * http\Client\Curl::$aws_sigv4
    * http\Client\Curl::$doh_url
    * http\Client\Curl::$dns_shuffle_addresses
    * http\Client\Curl::$haproxy_protocol
    * http\Client\Curl::$hsts
    * http\Client\Curl::$hsts_ctrl
    * http\Client\Curl::$http09_allowed
    * http\Client\Curl::$maxage_conn
    * http\Client\Curl::$pinned_publickey
    * http\Client\Curl::$proxy_ssl
    * http\Client\Curl::$socks5_auth
    * http\Client\Curl::$tcp_fastopen
    * http\Client\Curl::$tls13_ciphers
    * http\Client\Curl::$xoauth2_bearer
  * Added request option constants:
    * http\Client\Curl\AUTH_AWS_SIGV4
    * http\Client\Curl\AUTH_BEARER
    * http\Client\Curl\AUTH_NONE
    * http\Client\Curl\HTTP_VERSION_2_PRIOR_KNOWLEDGE
    * http\Client\Curl\HTTP_VERSION_3
    * http\Client\Curl\SSL_VERSION_MAX_*
    * http\Client\Curl\SSL_VERSION_TLSv1_3
  * Added library version constants:
    * http\Client\Curl\Versions\BROTLI
    * http\Client\Curl\Versions\CAINFO
    * http\Client\Curl\Versions\CAPATH
    * http\Client\Curl\Versions\HYPER
    * http\Client\Curl\Versions\ICONV
    * http\Client\Curl\Versions\NGHTTP2
    * http\Client\Curl\Versions\QUIC
    * http\Client\Curl\Versions\ZSTD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants