-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The .Str method gets confused by binary $.content in HTTP::Message #171
Comments
Hi, I guess, as long as the content-type is set appropriately, it could try harder, bearing in mind that it both wants to send actually binary data as well as text data that may be in an encoding that Perl doesn't know about (and thus needs to be a Blob) |
The my $res = HTTP::Response.new(200);
$res.content = buf8.new; # $.content has to be primed for binary
$res.add-content("Hello World".encode);
say $res.Str(:bin); # fails with or without bin The need for "priming" is a minor annoyance but might be considered a bug as well. |
Actually, that example does not work. I had not realized that my $res = HTTP::Response.new(200);
$res.content = buf8.new; # $.content has to be primed for binary
$res.add-content: buf8.new(0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64);
say $res.Str(bin => ?(rand <= 0.5)); # fails with or without bin The UserAgent itself avoids this problem. It would only come up with code that was putting bufs into the HTTP::Message without the help of UA, which had not yet been careful about encoding. Perhaps the onus is on the caller to be that careful instead. |
If I build an HTTP::Response object that places a Buf in $.content, the .Str method will fail with the following exception:
The text was updated successfully, but these errors were encountered: