Help with reqwest - Error(Http(Header))

I'm sure this is probably a very easy for most people, but I'm an academic so barely use things related to the web (in terms of programming). As such I was trying now to just get a simple API call but I keep getting this error which I have no idea why it is. I'm using the crate reqwest for the calls. Code can be found here: Rust Playground. On my machine I keep getting this error:

Err(Error { kind: Http(Header), url: Some("https://www.bitstamp.net/api/v2/trading-pairs-info/") })

I really did not figured what I'm missing here.

Have you tried not setting any headers at all? What do you see if you trace a similar curl request?

Sorry, not updating this and thanks to mbrubeck on IRC we discovered that the issue is that the website (bitstamp) provides a SetCookie header which contains non-US ASCII characters which is decaprated in header fields with an RFC. The hyper httparse crate enforces this strictly, hence the problem was in the response header rather than the one sending. Currently, except them fixing this I don't think there is any workaround.

1 Like

Interesting - thanks for coming back to mention the root cause.

A couple of thoughts:

  1. It seems the hyper message can be a bit clearer about what it didn’t like. At the very least, indicate that it’s some response (vs request) header. But ideally, it would include the actual header name. As it stands, this error is virtually useless as far as debugability is concerned.
  2. How do browsers handle this? I’m guessing they’re lenient. Why is httparse taking such a strict stance on it?
  1. I agree this can be improved quite a bit... I was left with the impression my headers were wrong for about a day.

  2. They seem to ignore the fact that there are characters which there should not be as they save them as a string. I guess it is strict from the perspective of security and safety as this is per this RFC RFC 7230 - Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing.