mockoon / mockoon

Mockoon is the easiest and quickest way to run mock APIs locally. No remote deployment, no account required, open source.
https://mockoon.com
Other
6.26k stars 370 forks source link

Improper handling of HTTP `Expect: 100-continue` header for POST requests with bodies #1126

Open dwandro opened 1 year ago

dwandro commented 1 year ago

Describe the bug

When Mockoon proxy server receives an HTTP POST request with Expect: 100-continue header and a body from the client, it does not respond with an HTTP 100 response. This prevents the client from sending the actual POST request with body, and causes the proxy call to fail with a timeout.

To Reproduce

To reproduce the current behavior
  1. Setup an environment with no routes and proxy to any address (http://www.google.com will suffice).
  2. Listen on any port (we will use port 3000 for the example).
  3. Send an HTTP POST call to Mockoon with an Expect: 100-continue header: curl -v http://127.0.0.1:3000/ -H 'Expect: 100-continue' -X POST -d '{"foo": "bar"}'
  4. The request will hang.
To work around the problem and produce the desired behavior
  1. Change the port that Mockoon is running on to something different (we will use port 3001 for the example).
  2. Setup NGINX to listen on the port that Mockoon was originally running on and proxy traffic to the port from step 1, removing the Expect header before sending the request to Mockoon:
    server {
      listen 3000 default_server;
      location / {
        proxy_set_header Expect "";
        proxy_pass http://localhost:3001;
     }
    }
  3. Send an HTTP POST call to NGINX with an Expect: 100-continue header: curl -v http://127.0.0.1:3000/ -H 'Expect: 100-continue' -X POST -d '{"foo": "bar"}'
  4. NGINX will respond with an HTTP 100 response, and the client will send the POST request (which will result in an error, because the upstream doesn't allow POST requests).
  5. The request does not hang.

Mockoon version:

6.1.0, 4.1.0

OS / OS version:

macOS 13.x, Windows 10, Ubuntu 22.04

SaintM commented 1 week ago

Just to add, this is still a bug in version 8.4.0.

As @dwandro outlined above, the fix to remove the header before hitting mockoon works around the issue.