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

when using http2 and SwooleResponse sendfile, Content-Type header is not respected #4492

Closed
abnud1 opened this issue Nov 15, 2021 · 2 comments

Comments

@abnud1
Copy link

abnud1 commented Nov 15, 2021

  1. What did you do? If possible, provide a simple script for reproducing the error.
    I have a javascript file already compressed using brotli at build time, I need to send it as a response with Content-Type: application/javascript, Content-Encoding: br.

This is the script I'm using:

#!/usr/bin/env php
<?php

use Swoole\Http\Request;
use Swoole\Http\Response;
use Swoole\Http\Server;

$server = new Server('0.0.0.0', 9503, SWOOLE_BASE);
$server->set(
    [
        'open_http2_protocol' => true,
    ]
);
$server->on(
    'request',
    function (Request $request, Response $response) {
        $response->header("content-type","application/javascript");
        $response->header("content-encoding","br");
        $response->sendfile("./test.js.br");
    }
);
$server->start(); 

consider
test.js.br.zip which contains test.js.br inside just as an example.

  1. What did you expect to see?
    using curl -i --http2-prior-knowledge http://server:950 I would expect to see this output:
HTTP/2 200 
content-type: application/javascript
content-encoding: br
server: swoole-http-server
date: Mon, 15 Nov 2021 20:41:13 GMT
content-length: 53685

Warning: Binary output can mess up your terminal. Use "--output -" to tell 
Warning: curl to output it to your terminal anyway, or consider "--output 
Warning: <FILE>" to save to a file.
  1. What did you see instead?
HTTP/2 200 
content-type: application/octet-stream
content-encoding: br
server: swoole-http-server
date: Mon, 15 Nov 2021 20:41:13 GMT
content-length: 53685

Warning: Binary output can mess up your terminal. Use "--output -" to tell 
Warning: curl to output it to your terminal anyway, or consider "--output 
Warning: <FILE>" to save to a file.
  1. What version of Swoole are you using (show your php --ri swoole)?

swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.8.1
Built => Nov 14 2021 09:07:25
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
openssl => OpenSSL 1.1.1l  24 Aug 2021
dtls => enabled
http2 => enabled
pcre => enabled
zlib => 1.2.11
brotli => E16777225/D16777225
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608
  1. What is your machine environment used (show your uname -a & php -v & gcc -v) ?
    uname -a: Linux 7607e75ef1a9 5.14.16-arch1-1 #1 SMP PREEMPT Tue, 02 Nov 2021 22:22:59 +0000 x86_64 GNU/Linux(Arch Linux x64)
    php -v: 8.0.12
    gcc -v: 11.1.0
matyhtf added a commit that referenced this issue Nov 23, 2021
matyhtf added a commit that referenced this issue Nov 24, 2021
* fix #4492

* Add tests

* fix

* fix 2
# Conflicts:
#	ext-src/swoole_http2_server.cc
#	ext-src/swoole_http_response.cc
@bitslip6
Copy link

This bug has regressed in 22.1.2 at least. Exact same issue, sendfile forces the content-type to the autodetected mime type

@leocavalcante
Copy link
Member

@bitslip6, please note that v22.1.2 corresponds to the OpenSwoole fork https://github.com/openswoole/ext-openswoole/releases not this official Swoole repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants