Confusion about HTTPotion response

I’m hoping this post isn’t off topic for this forum. I’m sending a http post to a REST endpoint leveraging HTTPotion and I’m getting the following response:

    %HTTPotion.ErrorResponse{
  message: "{:content_length_undefined, {:stat_code, '200'}, \"HTTP/1.1 200 OK\\r\\nContent-Type: application/vnd.dcp-v1+json\\r\\nDate: Wed, 19 Dec 2018 15:11:34 GMT\\r\\nAccess-Control-Allow-Origin: *\\r\\nAccess-Control-Allow-Methods: GET, POST, DELETE, PUT,OPTIONS\\r\\nAccess-Control-Allow-Headers: Content-Type, X-Access-Token\\r\\nAccess-Control-Expose-Headers: X-Access-Token\\r\\nSet-Cookie: c9c54d0c7a2119a88cbb4d1c8a1ef0d0=ed20f80f36ef856038563a2c27ff36ee; path=/; HttpOnly\"}"
}

what’s confusing me is why HTTPotion is treating this as an error when the status_code is 200? I thought of capturing the raw request and response on the wire, but because the endpoint is encrypted, this isn’t an option.

Any help would be greatly appreciated.

Thanks

:wave:

Seems like the response doesn’t have Content-Length header set. The way HTTPotion represents the error is funny though. Seems like it just inspects the error tuple from ibrowse.

Just in case, there is a way to decrypt https requests with wireshark.

3 Likes

I “figured it out” by switching to HTTPoison and passing hackney: [:insecure]. When I switched to HTTPoison it stated that the CA was unknown, so with this option it works. Curious that HTTPotion didn’t provide a more meaningful error.

This is not related to the certificate. HTTPotion/ibrowse ignore the server’s certificate unless you explicitly opt-in to peer certificate verification, whereas HTTPoison/hackney enable server certificate verification by default. See https://blog.voltone.net/post/7 (still relevant 2 years later, unfortunately).

The root cause is the lack of the “Content-Length” header in the response, as @idi527 pointed out . HTTPotion/ibrowse consider that a malformed response, while HTTPoison/hackney apparently make a best-effort attempt to handle the response despite the protocol violation.

2 Likes

I think your meant HTTPoison/hackney instead of HTTPotion/hackney (the last time you refer to it)

1 Like

Damn those HTTPuns, yes, thanks

1 Like

Thanks for detailed answer folks, much appreciated!

You should make an updated post with Tesla and Buoy too! Or update the existing one? :slight_smile: