m6w6 / ext-http

Extended HTTP Support
BSD 2-Clause "Simplified" License
79 stars 22 forks source link

Unexpected / Cached Result from "getRequestHeader" #90

Closed toitzi closed 3 years ago

toitzi commented 5 years ago

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

m6w6 commented 5 years ago

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

toitzi commented 5 years ago

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

m6w6 commented 5 years ago

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