[erlang-questions] misultin / unicode

Roberto Ostinelli roberto@REDACTED
Thu Sep 1 22:21:52 CEST 2011


2011/9/1 Slav Pankratov <gnoblin@REDACTED>

> Hello!
>
>  I'm using misultin to receive http calls, and they sometimes contain
> Russian symbols (unicode).
>
> **
>>
>> % handle a GET on /users/{username}
>> handle('GET', ["users", UserName], Req) ->
>>         io:format("~s~n", [UserName]),
>> 	Req:ok([{"Content-Type", "text/plain"}], "This is ~s's page.", [UserName]);
>
>
> In both terminal and browser I see incorrect output - what can be done about it?
>
> big thanks,
> Slav
>
>
hi slav,

this is not particularly related to misultin. when using uri you need to
ensure that these are properly encoded for HTTP. You also need to ensure
that the browser is rendering html encoded in UTF-8 so you should have in
your code:

% handle a GET on /users/{username}
handle('GET', ["users", UserName], Req) ->
    Req:ok([{"Content-Type", "text/html; charset=UTF-8"}], "This is ~s's
page.", [UserName]);

then, you may serve the page:

http://localhost:8080/users/%26%231055%3B%26%231088%3B%26%231080%3B%26%231074%3B%26%231077%3B%26%231090%3B

that will print;

This is Привет's page.

you probably also could read into IRI: http://tools.ietf.org/html/rfc3987

my 2c.

r.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110901/119280c5/attachment.htm>


More information about the erlang-questions mailing list