开发者

Erlang custom httpd module - how to send custom HTTP headers and Content-Type

I'm implementing a custom module for Erlang's httpd (inets) server. I can successfully respond with HTML content with the following implementation of do method:

do(_ModData) ->
    Body = "<html><body&开发者_运维技巧gt;Hello world</body></html>",
    {proceed, [{response, {200, Body}}]}.

but the problem is I cannot find a way to respond with custom headers and text/xml content type.

According to erlang httpd docs, I can respond with [{response,{response,Head,Body}}], where "Head is a key value list of HTTP header fields" (quote from the docs), but what should be the exact format of this list? I tried the following, but it gives 404:

do(_ModData) ->
    Body = "<html><body>Stats Placeholder</body></html>",
    Head = ["Content-Length", "40", "Content-Type", "text/html"],
    {proceed, [{response, {response, Head, Body}}]}.

Any help on this would be appreciated, the docs and examples for erlang httpd are really sparse...


Try [{content_length, "40"}, {content_type, "text/html"}]


Try [{"Content-Length", "40"}, {"Content-Type", "text/html"}]


LOL. Is in the doc.

[{code, 200}, {content_length, "40"}, {content_type, "text/html"}]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜