{"action":"opened","issue":{"url":"https://api.github.com/repos/sergot/http-useragent/issues/68","labels_url":"https://api.github.com/repos/sergot/http-useragent/issues/68/labels{/name}","comments_url":"https://api.github.com/repos/sergot/http-useragent/issues/68/comments","events_url":"https://api.github.com/repos/sergot/http-useragent/issues/68/events","html_url":"https://github.com/sergot/http-useragent/issues/68","id":108557152,"number":68,"title":"Nicer handling of malformed utf8","user":{"login":"avuserow","id":82250,"avatar_url":"https://avatars.githubusercontent.com/u/82250?v=3","gravatar_id":"","url":"https://api.github.com/users/avuserow","html_url":"https://github.com/avuserow","followers_url":"https://api.github.com/users/avuserow/followers","following_url":"https://api.github.com/users/avuserow/following{/other_user}","gists_url":"https://api.github.com/users/avuserow/gists{/gist_id}","starred_url":"https://api.github.com/users/avuserow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/avuserow/subscriptions","organizations_url":"https://api.github.com/users/avuserow/orgs","repos_url":"https://api.github.com/users/avuserow/repos","events_url":"https://api.github.com/users/avuserow/events{/privacy}","received_events_url":"https://api.github.com/users/avuserow/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-09-27T19:54:08Z","updated_at":"2015-09-27T19:54:08Z","closed_at":null,"body":"I've seen some APIs that have a bad encoding specified in the content-type header, usually when dealing with a bad request. Currently HTTP::UserAgent provides no way of getting the raw bytes in this case.\r\n\r\nIf you have `plackup` from Perl 5's Plack module, we can demonstrate like so:\r\n\r\nserver: `plackup -e'sub {return [200, [], [\"hello world\\xff\\xff\\n\"]]}'`\r\nclient: `perl6 -MHTTP::UserAgent -e'my $ua = HTTP::UserAgent.new; my $r = $ua.get(\"http://localhost:5000/\"); say $r.content; say $r.decoded-content'`\r\n\r\noutput:\r\n>(Any)\r\n>Method 'bytes' not found for invocant of class 'Any'\r\n>  in method decoded-content at /home/ak/.rakudobrew/moar-nom/install/share/perl6/site/lib/HTTP/Message.pm6:24\r\n>  in block <unit> at -e:1\r\n\r\nMy suggestion: If the decoded-content method fails when decoding, raise an exception (or a failure?) which has a `bytes` attribute with the raw bytes of the HTTP response. This would allow a user to manually decode it to ASCII, Latin-1, or just inspect the bytes to see if there is any useful information for making a proper request."}}