openresty / lua-nginx-module

Embed the Power of Lua into NGINX HTTP servers
https://openresty.org/
11.26k stars 2.03k forks source link

HTTP/2 with location.capture() re-enable #2243

Open oowl opened 11 months ago

oowl commented 11 months ago

I have tried to reproduce https://github.com/openresty/lua-nginx-module/issues/1195#issue-275974888 mentioned bug by revert https://github.com/openresty/lua-nginx-module/commit/3078ca6138121a98e22104b9f7015b31d312861b commit

user root;
worker_rlimit_core 500M;

events {
    worker_connections 1024;
}

http {
    log_format compression '$remote_addr - $remote_user [$time_local] '
                        '"$request" $status $bytes_sent '
                        '"$http_referer" "$http_user_agent" "$gzip_ratio"';
    access_log logs/access.log compression;
            proxy_cache_path /tmp/nginx/cache keys_zone=api_key:10m;
    server {
        listen 8080 http2;
        location /main2 {
            content_by_lua '
                local res2 = ngx.location.capture("/internal/api",  {
                    method = ngx.HTTP_POST,
                    body = body,
                    args = {hello = "world"}
                })
                ngx.say(res2.body)
            ';
        }
        location /foo {
            echo -n world;
        }
        location /bar {
            echo -n ' people';
        }
        location = /internal/api {
            internal;
            proxy_method GET;
            proxy_cache_methods GET HEAD POST;
            proxy_cache_valid any 5m;
            proxy_cache api_key;
            proxy_cache_key api_$args;
            proxy_pass https://httpbin.org/anything;
        }
    }
}
curl --http2-prior-knowledge 127.0.0.1:8080/main2/api\?a=1  -H "accept: application/json" -X POST -vv
*   Trying 127.0.0.1:8080...
* Connected to 127.0.0.1 (127.0.0.1) port 8080
* [HTTP/2] [1] OPENED stream for http://127.0.0.1:8080/main2/api?a=1
* [HTTP/2] [1] [:method: POST]
* [HTTP/2] [1] [:scheme: http]
* [HTTP/2] [1] [:authority: 127.0.0.1:8080]
* [HTTP/2] [1] [:path: /main2/api?a=1]
* [HTTP/2] [1] [user-agent: curl/8.4.0]
* [HTTP/2] [1] [accept: application/json]
> POST /main2/api?a=1 HTTP/2
> Host: 127.0.0.1:8080
> User-Agent: curl/8.4.0
> accept: application/json
> 
< HTTP/2 200 
< server: openresty/1.21.4.2
< date: Thu, 19 Oct 2023 15:32:30 GMT
< content-type: text/plain
< 
{
  "args": {
    "hello": "world"
  }, 
  "data": "", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "application/json", 
    "Host": "httpbin.org", 
    "User-Agent": "curl/8.4.0", 
    "X-Amzn-Trace-Id": "Root=1-65314b87-0647d43721dc60d564c46b16"
  }, 
  "json": null, 
  "method": "GET", 
  "url": "https://httpbin.org/anything?hello=world"
}

curl --http2-prior-knowledge 127.0.0.1:8080/main2/api\?a=1  -H "accept: application/json" -X POST -vv
*   Trying 127.0.0.1:8080...
* Connected to 127.0.0.1 (127.0.0.1) port 8080
* [HTTP/2] [1] OPENED stream for http://127.0.0.1:8080/main2/api?a=1
* [HTTP/2] [1] [:method: POST]
* [HTTP/2] [1] [:scheme: http]
* [HTTP/2] [1] [:authority: 127.0.0.1:8080]
* [HTTP/2] [1] [:path: /main2/api?a=1]
* [HTTP/2] [1] [user-agent: curl/8.4.0]
* [HTTP/2] [1] [accept: application/json]
> POST /main2/api?a=1 HTTP/2
> Host: 127.0.0.1:8080
> User-Agent: curl/8.4.0
> accept: application/json
> 
< HTTP/2 200 
< server: openresty/1.21.4.2
< date: Thu, 19 Oct 2023 15:36:08 GMT
< content-type: text/plain
< 
{
  "args": {
    "hello": "world"
  }, 
  "data": "", 
  "files": {}, 
  "form": {}, 
  "headers": {
    "Accept": "application/json", 
    "Host": "httpbin.org", 
    "User-Agent": "curl/8.4.0", 
    "X-Amzn-Trace-Id": "Root=1-65314ce8-504043c862ceaf6a48dbe6ce"
  }, 
  "json": null, 
  "method": "GET", 
  "url": "https://httpbin.org/anything?hello=world"
}

I can not reproduce this problem, Just wanted to know if it's possible to revert the https://github.com/openresty/lua-nginx-module/commit/3078ca6138121a98e22104b9f7015b31d312861b commit to enable HTTP2 location.capture() support.

oowl commented 11 months ago

If anyone can help me to reproduce this problem, I would be very willing to dig it up and fix it.

oowl commented 2 months ago

Hi team, for a long time, there has been no progress on this issue. However, some of our code relies on this API for cache-related work. This means that for a long time, our caching functionality hasn't worked over HTTP2 because of this hard-coded limitation. Our service does not involve any internal proxy_cache features, so it shouldn't be affected. Therefore, I believe we should remove this hard-coded limit because the impact of not being able to use it at all is greater than the potential bugs that might arise. cc @zhuizhuhaomeng @agentzh

oowl commented 2 months ago

also cc @wangchunpeng

Navinnair commented 1 month ago

Hi @oowl

Thank you for your ongoing work on this module. I wanted to ask if there are any plans to address the HTTP/2 issue that has been discussed. Specifically, is there any intention to revert the changes mentioned, or will there be a different fix implemented?

I understand that maintaining such a project requires a lot of time and effort, and I truly appreciate all that you do. Any updates or insights you could share would be highly appreciated.

Thanks in advance!

oowl commented 1 month ago

Hi @oowl

Thank you for your ongoing work on this module. I wanted to ask if there are any plans to address the HTTP/2 issue that has been discussed. Specifically, is there any intention to revert the changes mentioned, or will there be a different fix implemented?

I understand that maintaining such a project requires a lot of time and effort, and I truly appreciate all that you do. Any updates or insights you could share would be highly appreciated.

Thanks in advance!

Sorry, I am not a maintainer of Openresty, so I can not answer your problem.