HTTP server: Persistent connection on HTTP/1.0 hangs, when using streaming response body

Aperta
#552 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
php
Ambito
api, backend

Direzione di ricerca

Start at src/Io/StreamingServer.php around line 308 and reproduce the issue with the provided streaming ThroughStream example and curl --http1.0 request. Trace how an HTTP/1.0 response with an unknown body size handles Connection: keep-alive; done means the response is transmitted and the connection closes instead of hanging.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

Assuming the response body is streaming and its size is unknown, when a request such as this is received:

GET / HTTP/1.0
Connection: keep-alive

ReactPHP produces a response without a Content-Length header, such as this:

HTTP/1.0 200 OK
Connection: keep-alive

<data>

and doesn't close the connection, which then just hangs until timeout, because for the client there is no way of telling, when the response data is finished transmitting.

Steps to reproduce:

$server = new React\Http\HttpServer(function () {
    $stream = new ThroughStream();
    Loop::futureTick(function () use ($stream) {
        $stream->write("foo\n");
        $stream->end();
    });
    return new Response(200, body: $stream);
});

$socket = new React\Socket\SocketServer("0.0.0.0:80");
$server->listen($socket);
curl -v --http1.0 -H "connection: keep-alive" localhost:80

Tested on v1.11.0 and 3.x-dev (4e1b4f369eea9428ac38b8851e113ce5ad47cbee).


Since it's HTTP/1.0, Transfer-Encoding: chunked cannot be used. I believe the only good way to handle this situation is to ignore the requested Connection: keep-alive and just close the connection after the response is transmitted. I think this should be a valid behavior - server is not required to strictly obey the keep-alive request header.

The relevant code is here: https://github.com/reactphp/http/blob/1.x/src/Io/StreamingServer.php#L308

Lingua principale
PHP
Stelle
781
Fork
166
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di reactphp/http

Tutte le issue di reactphp/http

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.