Erlang 自定义 httpd 模块 - 如何发送自定义 HTTP 标头和 Content-Type
我正在为 Erlang 的 httpd (inets) 服务器实现一个自定义模块。我可以通过以下 do
方法的实现成功地响应 HTML 内容:
do(_ModData) ->
Body = "<html><body>Hello world</body></html>",
{proceed, [{response, {200, Body}}]}.
但问题是我找不到响应自定义标头和 text/xml
内容类型的方法。
根据 erlang httpd 文档,我可以使用 [{response,{response,Head,Body}}]
进行响应,其中“Head 是 HTTP 标头字段的键值列表”(引用自文档) ,但是这个列表的确切格式应该是什么?我尝试了以下操作,但它给出了 404:
do(_ModData) ->
Body = "<html><body>Stats Placeholder</body></html>",
Head = ["Content-Length", "40", "Content-Type", "text/html"],
{proceed, [{response, {response, Head, Body}}]}.
对此的任何帮助将不胜感激,erlang httpd 的文档和示例非常稀疏......
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试
[{content_length, "40"}, {content_type, "text/html"}]
Try
[{content_length, "40"}, {content_type, "text/html"}]
尝试 [{"Content-Length", "40"}, {"Content-Type", "text/html"}]
Try [{"Content-Length", "40"}, {"Content-Type", "text/html"}]
哈哈。在文档中。
LOL. Is in the doc.