Uploaded image for project: 'Red Hat 3scale API Management'
  1. Red Hat 3scale API Management
  2. THREESCALE-9542

Add support for chunked requests

    • Add support for chunked requests
    • False
    • None
    • False
    • Not Started
    • Not Started
    • Not Started
    • Not Started
    • Not Started
    • Not Started
    • 100% To Do, 0% In Progress, 0% Done

      Current behaviour

      When a request with the HTTP header Transfer-Encoding: chunked is sent APIcast buffers the whole request as by default it doesn't support sending chunked requests. However, the header sent in the original request telling the server that the client is chunking the request should be removed otherwise the upstream will not be able to determine the end of the request. The HTTP 1.1 RFC states that if requests are chunked and therefore the header Transfer-Encoding: chunked is present then the header Content-Length must not be present and therein lies the problem for any upstreams with persitent connections.

      Additionally, it should be possible to enable chunked requests. Normally this is achievable by configuring the directive proxy_request_buffering off; due to the default being on: http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_request_buffering. For this to be possible THREESCALE-8410 needs to be implemented and maybe this specific directive should be treated separately and a new RFE created.

      Lastly, as a workaround it should be possible to modify the nginx.conf to disable the proxy_request_buffering and this is true unless an HTTP proxy is being used with APIcast. As the requests that go through proxies (including the camel proxy policy) are executed in Lua then this directive is not respected and thus the integration is blocked. This will need to be fixed in all the modules where HTTP proxy forwarding is performed by APIcast. It looks like the lib we use in these modules already has support for chunked requests that we should be able to leverage.

      Expected behaviour

      When a request with the HTTP header Transfer-Encoding: chunked is sent APIcast does not buffer the request and sends it immediately according to the RFC whether APIcast is forwarding traffic via an HTTP proxy, the Camel Proxy policy or otherwise.

      Upstream logs from reproducer environment (using HTTP/HTTPS forward proxy with APIcast and a second APIcast as the upstream)

      When traffic is forwarded to an upstream over HTTPS:

      2023/04/13 11:33:40 [error] 29#29: *2 client sent invalid chunked body, client: 10.217.0.2, server: _, request: "POST /anything?user_key=foo HTTP/1.1", host: "apicast-upstream-service"
      

      When traffic is forwarded to an upstream over HTTP:

      [13/Apr/2023:11:36:56 +0000] apicast-upstream-service:8080 10.217.0.2:60514 "POST /anything?user_key=foo HTTP/1.0" 200 764 (12.500) 0
      

      The reason for this is because the forward proxy doesn't forward client headers over HTTP and so the upstream server in this test doesn't receive the Transfer-Encoding: chunked header (even though APIcast does send it).

      When the request to the upstream is over HTTPS the CONNECT method is used and therefore all client request parameters are preserved and the failure is observed.

              Unassigned Unassigned
              rhn-support-keprice Kevin Price
              Matej Dujava Matej Dujava
              An Tran An Tran
              Votes:
              1 Vote for this issue
              Watchers:
              15 Start watching this issue

                Created:
                Updated: