Expect: 100-continue with the nginx proxy_pass

simanto604 nginx-forum at forum.nginx.org
Wed Apr 24 07:14:08 UTC 2019


We are integrating a 3rd party payment gateway which on a successful
transaction sends a [IPN][1] request. So we have built a API endpoint to
handle the request which works fine in dev env. 

Now the issue is when we use nginx infront of the API Server it gets 301
redirects. When we are using a proxy tunnel like [ngrok][2], which proxies
the http request via ngrok servers, the request passes through nginx to our
API server successfully but when the IPN POST request is directly served to
our nginx it gets a 301 redirect. To dig deeper we intercept the request
with a python [SimpleHttpServer][3] leading us to find the difference of
http headers:

 - without ngrok (direct to nginx)

> ['Host: 35.154.216.72:4040\r\n', 'Accept: */*\r\n', 'Content-Length:
> 1030\r\n', 'Content-Type: application/x-www-form-urlencoded\r\n',
> '**Expect: 100-continue**\r\n']

 - With ngrok

> ['Host: 543fdf1c.ngrok.io\r\n', 'Accept: */*\r\n', 'Content-Length:
> 1013\r\n', 'Content-Type: application/x-www-form-urlencoded\r\n',
> 'X-Forwarded-For: 2a01:4f8:192:22ec::2\r\n']

We are assuming the issue lies with the `Expect: 100-continue` headers. So
the question is there any way to handle this with Nginx? or what is the
industry standard solution for such scenerio?

FYI: Nginx conf: 

    location /api/ {

    proxy_set_header Expect $http_expect;
    client_body_in_file_only on;
    proxy_pass_request_headers      on;
    proxy_http_version 1.1;

    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header Upgrade $http_upgrade;
    #proxy_set_header Connection 'upgrade';
    proxy_set_header Connection keep-alive;
    proxy_set_header Host $host;
    proxy_pass_header X-CSRFToken;
    #proxy_pass_header csrftoken;
    proxy_cache_bypass $http_upgrade;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://kk-api;
    }
IPN endpoint is `/api/v1/ipn`
  [1]: https://en.wikipedia.org/wiki/Instant_payment_notification
  [2]: http://www.ngrok.com
  [3]: https://docs.python.org/2/library/simplehttpserver.html

For better have a better preview the question is also posted in
StackOverflow:
https://stackoverflow.com/questions/55810543/nginx-handle-expect-100-continue-header

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,283902,283902#msg-283902



More information about the nginx mailing list