Returning erlang term_to_binary to browser, char 65533 not 131 at [0]

10 views
Skip to first unread message

Russell

unread,
Oct 29, 2009, 5:04:33 PM10/29/09
to MochiWeb
Hi,
This is probably not a mochiweb thing, more a web thing but: I have a
module that creates a tuple. This tuple is then converted to a binary
using term_to_binary(Tuple). I then return this binary to the client
( {200, [{"Content-Type", "text/plain"}], Term}; ).

On the client,when I look at the returned data the first char has
become 65533 (unicode Character 'REPLACEMENT CHARACTER' (U+FFFD)) not
the char 131 that I would expect to see as the first character.

This is all 'cos I am playing with BERT-JS. I can get around it just
by knocking off the 1st char of the response and replacing it with 131
but if anyone has the time to take pity and give me a clue I would be
grateful.

Cheers

Russell

Steve Davis

unread,
Oct 29, 2009, 5:37:09 PM10/29/09
to MochiWeb
using {"Content-Type", "application/octet-stream"} ...would make more
sense.

Bob Ippolito

unread,
Oct 29, 2009, 6:49:30 PM10/29/09
to moch...@googlegroups.com
On Thu, Oct 29, 2009 at 5:04 PM, Russell <miste...@googlemail.com> wrote:
>
> Hi,
> This is probably not a mochiweb thing, more a web thing but: I have a
> module that creates a tuple. This tuple is then converted to a binary
> using term_to_binary(Tuple). I then return this binary to the client
> ( {200, [{"Content-Type", "text/plain"}], Term}; ).
>
> On the client,when I look at the returned data the first char has
> become 65533 (unicode Character 'REPLACEMENT CHARACTER' (U+FFFD)) not
> the char 131 that I would expect to see as the first character.

The problem is in your client, not in the server. Although
"text/plain" is a weird content-type for binary data and you should
probably fix that, it sounds like your client is parsing the body as a
UTF-8 string instead of leaving it as binary. Obviously you're not
going to see any values outside of [0-255] if your client is properly
reading the body as binary octets.

-bob

Russell

unread,
Nov 1, 2009, 9:09:50 AM11/1/09
to MochiWeb


On Oct 29, 10:49 pm, Bob Ippolito <b...@redivi.com> wrote:
Ok, thanks for that. I made the changes to my content type. I'm still
seeing the client behaviour so I'll dig into that more.

Thanks again for the help

Russell
Reply all
Reply to author
Forward
0 new messages