unbit / uwsgi

uWSGI application server container
http://projects.unbit.it/uwsgi
Other
3.45k stars 691 forks source link

`collect-header` not collecting headers #1456

Open robbietjuh opened 7 years ago

robbietjuh commented 7 years ago

I've been scratching my head for a few hours on this one and I'm about to believe that this might be a bug. I have the following configuration snippet:

plugin = 0:php

collect-header = X-Sendfile X_SF
response-route-if-not = empty:${X_SF} addheader:X-Test: yes
response-route-if = empty:${X_SF} addheader:X-Test: no

The following is logged, indicating that these rules are successfully getting applied:

*** Starting uWSGI 2.0.14 (64bit) on [Sun Jan 22 03:55:03 2017] ***
[....]
*** dumping internal response routing table ***
[rule: 0] subject: ${X_SF} func: !empty action: addheader:X-Test: yes
[rule: 1] subject: ${X_SF} func: empty action: addheader:X-Test: no
*** end of the internal response routing table ***
collecting header X-Sendfile to var X_SF

However, it seems the rules are not working:

$ curl -I http://localhost:8000
HTTP/1.1 200 OK
Content-type: text/html
X-Sendfile: test
X-Test: no

I've tested this with the latest uWSGI build and the default profile. I'm using the php plugin and a very simple header('X-Sendfile: test'); to test it out.

Let me know if you need any more info. I'd be glad to help out.

daltonmatos commented 7 years ago

I'm having this very same problem. I'm using uwsgi==2.0.15

nfvs commented 7 years ago

+1 using 2.0.15, tried all kinds of headers. Content-Type was the only one that worked, all others were seemingly ignored. Also tried both --http and --http-socket.

nfvs commented 7 years ago

Here's an easy test with the router_redirect plugin (should redirect all requests that don't have the header X-Test: test):

uwsgi --plugins=router_redirect --processes=1 --http-socket=0.0.0.0:80 --collect-header="X-Test TEST" --route-if-not='equal:${TEST};test redirect-permanent:https://${HTTP_HOST}/header=${TEST}'

And with curl:

❯ curl http://127.0.0.1:8088/ -Iv -H "X-Test: http"
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8088 (#0)
> HEAD / HTTP/1.1
> Host: 127.0.0.1:8088
> User-Agent: curl/7.54.0
> Accept: */*
> X-Test: http
>
< HTTP/1.1 301 Moved Permanently
HTTP/1.1 301 Moved Permanently
< Location: http://127.0.0.1:8088/header=
Location: http://127.0.0.1:8088/header=

<
* Excess found in a non pipelined read: excess = 17 url = / (zero-length body)
* Connection #0 to host 127.0.0.1 left intact

Should be redirecting to http://127.0.0.1:8088/header=http.

tnt-dev commented 3 years ago

I have ran into the same issue and after a short investigation I have found that it happens with uwsgi built without pcre support. You should install libpcre headers package and rebuild uwsgi or find prebuilt version with pcre support. I hope it helps somebody and it looks like that issue could be closed.