简体   繁体   中英

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>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...

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

LOL. Is in the doc.

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

尝试[{“ Content-Length”,“ 40”},{“ Content-Type”,“ text / html”}]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM