file_get_contents should probably clear the global state of last headers
Nessuno ha ancora preso questa issue.
- Lingua principale
- C
- Stelle
- 40.4k
- Fork
- 8.1k
- Merge medio
- 2g 13h
- PR unite (30g)
- 96
Descrizione
Description
The following code:
<?php
file_get_contents(__FILE__);
var_dump(http_get_last_response_headers());
file_get_contents('https://php.net/');
var_dump(http_get_last_response_headers());
file_get_contents(__FILE__);
var_dump(http_get_last_response_headers());
Resulted in this output:
NULL
array( headers from php.net )
array( headers from php.net )
But I expected this output instead:
NULL
array( headers from php.net )
NULL // as reading a file clearly outputs no headers
IMO this is very surprising, and can lead to bugs (see https://github.com/jsonrainbow/json-schema/pull/843 for example) as people are now nudged to switch to http_get_last_response_headers() by the deprecations.
The problem is that $http_response_headers, while a very ugly API, was a local variable.. and http_get_last_response_headers() while appearing cleaner stores global state and can thus leak data across boundaries if you do not call http_clear_last_response_headers() after fetching the headers.
Thus my suggestion would be that file_get_contents first clears the headers and then populates them if the stream wrapper in use has anything to populate.
/cc @Girgias as I know you were involved in the deprecation. And apologies if this was already discussed somewhere I didn't find.
PHP Version
All versions where `http_get_last_response_headers()` is available
Operating System
No response
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia eseguendo la riproduzione PHP nell'issue e leggendo le implementazioni di file_get_contents(), http_get_last_response_headers() e http_clear_last_response_headers(). Traccia il modo in cui gli stream wrapper aggiornano gli header memorizzati, quindi aggiungi una verifica che dimostri che la lettura di un file locale cancella gli header lasciati da una precedente richiesta HTTP; il lavoro è completato quando la chiamata finale restituisce NULL.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- c, php
- Ambito
- backend-api-design
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 48/100