CurtTilmes / raku-libcurl

A Raku interface to libcurl.
Other
19 stars 9 forks source link

fetching binary content #9

Closed ufobat closed 6 years ago

ufobat commented 6 years ago

Hello, I have got a "broken" webserver that offers me a chunk of binary data but unfortunatelly sets this header: Content-Type: text/plain;charset=UTF-8. Bechause the $encoding information in the header overrides the $encoding provided in the method call to content it is impossible to fetch the data. ( I was assuming that i could decode $random_data with latin1 )

CurtTilmes commented 6 years ago

.content will decode the incoming data, but you can always get the raw data with .buf.

https://github.com/CurtTilmes/perl6-libcurl#content

ufobat commented 6 years ago

right, thanks! but should the response override the $encoding parameter, if the user specifies one?

CurtTilmes commented 6 years ago

The $encoding parameter sets a default that is used if the server doesn't tell you its encoding. I don't think that should change.

With the broken server lying to you, you should a) contact the server's owner and ask them to fix it, and b) just use .buf.decode('latin1') or whatever to decode it however you want.

ufobat commented 6 years ago

Allright :) thanks dir your Feedback!