Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

HTTP/1.1 response to the Client of 1.0 #502

Open
@ngyuki

Description

@ngyuki
# create project from zend-expressive-skeleton
composer create-project zendframework/zend-expressive-skeleton .

# run container
docker run --rm -p 8080:80 -v "$PWD:/app" -w "/app" php:apache sh -c '
  a2enmod rewrite
  rmdir /var/www/html
  ln -s /app/public /var/www/html
  exec apache2-foreground
'

# run curl in other terminal, and see response
curl -i -0 http://localhost:8080/

curl request is HTTP/1.0, but zend-expressive has HTTP/1.1 response.

HTTP/1.1 200 OK
Date: Wed, 26 Jul 2017 10:46:48 GMT
Server: Apache/2.4.10 (Debian)
X-Powered-By: PHP/7.1.7
Content-Length: 151
Content-Type: application/json

:

Next, I tried ApacheBench.

ab -c 1 -n 1 http://localhost:8080/

Very very slow.

:
Requests per second:    0.20 [#/sec] (mean)
Time per request:       5021.594 [ms] (mean)
Time per request:       5021.594 [ms] (mean, across all concurrent requests)
:

ApacheBench expect active close of server, but server does not close until KeepAliveTimeout seconds.


This problem can solved by fix response protocol version based on request protocol version.

// pipeline.php

use Psr\Http\Message\ServerRequestInterface;
use Interop\Http\ServerMiddleware\DelegateInterface;

$app->pipe(function (ServerRequestInterface $request, DelegateInterface $delegate) {
    return $delegate->process($request)->withProtocolVersion($request->getProtocolVersion());
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions