httpc icon indicating copy to clipboard operation
httpc copied to clipboard

Response type needs to have a different body type

Open CrowdHailer opened this issue 4 years ago • 4 comments

currently the return type from httpc.send is Response(String)

https://hexdocs.pm/gleam_httpc/gleam/httpc/#send

This has been causing me runtime errors because I can use httpc to fetch resources like images, e.g. favicons which to not have a string body. I think the correct thing to do is Response(BitString)

CrowdHailer avatar Dec 16 '20 09:12 CrowdHailer

I've found the send_bits function. Interesting because I can send a request with type string and get a response with bit_string. and visa versa.

Not sure what the right answer is here.

CrowdHailer avatar Dec 16 '20 10:12 CrowdHailer

There's a tension between flexibility and doing what is useful in the majority of cases. For now we can case a string body to a bit string and use send_bits. What do you think?

lpil avatar Dec 16 '20 10:12 lpil

Hmm. I'm not sure. a dynamic string as the error is not very useful. Problem is sometimes I get a nonstring response from a CDN or proxy on occasion as much as the endpoint is set up to return proper strings

Don't think I have any useful answers,

CrowdHailer avatar Dec 17 '20 14:12 CrowdHailer

I'm not sure what you mean by dynamic string? It would be a bit string which could be printed or converted to a string if valid utf8.

lpil avatar Dec 17 '20 14:12 lpil