imposter icon indicating copy to clipboard operation
imposter copied to clipboard

Proxy mode: HTTP code 200 returned when backend reply body is empty

Open hilsonp opened this issue 2 years ago • 3 comments
trafficstars

When using imposter proxy http://my.backend/foo/bar, we have a case where the backend replies with an HTTP 204 and an empty body.

In this case, imposter (in proxy mode) will reply with the empty body but with an HTTP 200 instead of the HTTP 204. It is therefore not transparent.

Do you want me to provide two minimalist mock configuration demonstrating the problem ?

hilsonp avatar May 11 '23 09:05 hilsonp

Hi @hilsonp, yes please - this definitely sounds like a bug. A minimal demo would be very helpful, thank you.

outofcoffee avatar May 12 '23 00:05 outofcoffee

@outofcoffee Do not close it yet. I'll try to find some time to provide you with more info. Just need some time...

hilsonp avatar Jun 12 '23 07:06 hilsonp

Here is the way to reproduce it.

I create a mock of my provider: provider\provider-config.yaml

plugin: rest

resources:
  - path: "/get_204_nobody"
    response:
      statusCode: 204

I start an imposter using it listening on 8081: imposter.exe up provider -p 8081

I curl this provider directly and get the expected 204 with no body:

curl -v http://127.0.0.1:8081/get_204_nobody
*   Trying 127.0.0.1:8081...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8081 (#0)
> GET /get_204_nobody HTTP/1.1
> Host: 127.0.0.1:8081
> User-Agent: curl/7.65.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 204 No Content
< X-Imposter-Request: 1f0d2ad0-1575-403c-9fc8-1647bcce9a33
< Server: imposter
<
* Connection #0 to host 127.0.0.1 left intact

I start an imposter in proxy mode in front of that provider, listening on port 8080: imposter proxy http://127.0.0.1:8081/

I curl this imposter proxy and get a 200 with no body:

curl -v http://127.0.0.1:8080/get_204_nobody
*   Trying 127.0.0.1:8080...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> GET /get_204_nobody HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.65.0
> Accept: */*
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: imposter
< X-Imposter-Request: 914fa3aa-c398-4baa-bbaf-3b42946905a5
< Date: Thu, 15 Jun 2023 22:26:37 GMT
< Content-Length: 0
<
* Connection #0 to host 127.0.0.1 left intact

The log of the provider imposter is the same for both curl.

The log of the proxy imposter is the following:

imposter proxy http://127.0.0.1:8081/
time="2023-06-16T00:26:23+02:00" level=info msg="starting proxy for upstream http://127.0.0.1:8081/ on port 8080"
time="2023-06-16T00:26:37+02:00" level=debug msg="received request GET /get_204_nobody from client 127.0.0.1:59088"
time="2023-06-16T00:26:37+02:00" level=debug msg="invoking upstream http://127.0.0.1:8081/ with GET /get_204_nobody [body: 0 bytes]"
time="2023-06-16T00:26:37+02:00" level=debug msg="upstream responded to GET http://127.0.0.1:8081/get_204_nobody with status 204 [body 0 bytes]"
time="2023-06-16T00:26:37+02:00" level=debug msg="wrote response [status: 204, body 0 bytes] to client 127.0.0.1:59088"
time="2023-06-16T00:26:37+02:00" level=info msg="proxied GET /get_204_nobody to upstream [status: 204, body 0 bytes] for client 127.0.0.1:59088 in 4.9871ms"
time="2023-06-16T00:26:37+02:00" level=debug msg="empty response body for GET /get_204_nobody"
time="2023-06-16T00:26:37+02:00" level=debug msg="wrote config file C:\\Users\\ME\\Documents/127.0.0.1-8081-config.yaml for GET /get_204_nobody"

The content of the 127.0.0.1-8081-config.yaml file is:

plugin: rest
resources:
- method: GET
  path: /get_204_nobody
  response:
    headers:
      X-Imposter-Request: 914fa3aa-c398-4baa-bbaf-3b42946905a5
    statusCode: 204

hilsonp avatar Jun 15 '23 22:06 hilsonp