supernovus / perl6-http-client

Build HTTP Clients easily with Perl 6
18 stars 11 forks source link

Can't upload binary data #19

Open Tyil opened 7 years ago

Tyil commented 7 years ago

Trying to upload a binary encoded file currently fails due to a bug in lib/HTTP/Client/Request.pm6 on line 218. The error given is

Cannot use a Buf as a string, but you called the Stringy method on it

The code I used to call it was as follows:

$request.add-file(
    :name($distname),
    :filename($distname),
    :type("application/gzip")
    :content($dist.IO.slurp(:bin))
    :binary
);

I've discussed this in #perl6 for a bit, and gotten some information there. It might be helpful to you.

right, but it's concatenating the supplied binary data (the POST's content) and a final CRLF into a Str. which will treat it as Unicode in NFG and do things like trying to normalize it

yeh, it's building an http request in a Str. I'd argue that's wrong from the very start; it should be using a buf8, any Str-s put into it should be encoded as specified by encoding headers or otherwise .. pedantically ought to reject but practically likely needs to use iso8859-1

supernovus commented 7 years ago

This is a known issue, when the library was originally written, there was no buf support in Rakudo. If I recall, I was planning a rewrite in the '2.0' branch that I never did complete. This whole library is probably overdue for a massive rewrite. I simply haven't had time to work on any of my Perl 6 libraries in the last couple of years. As I don't know when I'll be able to get back to them, if someone in the community wants to take over maintenance of this library, I'd be happy to hand out some commit bits. I do want to eventually get back to the rewrite as it was planned to make it more stable and extendable.

avalenn commented 6 years ago

Waiting for the rewrite is it possible to advertise better the problems with the current state of the implementation and advice potential users to use another more mature library as Net::HTTP or HTTP::UserAgent ? (I know that I am repeating myself on several issues instead of proposing the right patches on README file. I will try to be more helpful next time.)

supernovus commented 6 years ago

I have updated the README to mention how broken this library is right now, and to suggest alternatives.

avalenn commented 6 years ago

Thank you.