如何在Erlang中更改mime_type?

时间:2013-06-11 05:03:23

标签: erlang mime-types

httpd:info(Pid).
      [{mime_types,[{"html","text/html"},{"htm","text/html"}]},
      {server_name,"httpd_test"},
      {bind_address, {127,0,0,1}},
      {server_root,"/tmp"},
      {port,59408},
      {document_root,"/tmp/htdocs"}]

当我确认httpd信息时,我看到了mime_type {“html”,“text / html”}。但我想这些类型添加application / x-www-form-urlencoded 应用程序/ JSON 应用/二郎二进制

但我找不到方法。

这是API文档。     行政财产

{mime_types, [{MimeType, Extension}] | path()}
Where MimeType = string() and Extension = string(). Files delivered to the client are MIME typed according to RFC 1590. File suffixes are mapped to MIME types before file delivery. The mapping between file suffixes and MIME types can be specified as an Apache like file as well as directly in the property list. Such a file may look like:

# MIME type Extension  
text/html   html htm
text/plain  asc txt

Defaults to [{"html","text/html"},{"htm","text/html"}]

{mime_type, string()}
When the server is asked to provide a document type which cannot be determined by the MIME Type Settings, the server will use this default type.

我如何解决问题?

1 个答案:

答案 0 :(得分:0)

-module(hello_world).
-export([start/0,service/3]).

start() ->
inets:start(httpd, [
{modules, [
mod_alias, 
mod_auth, 
mod_esi, 
mod_actions, 
mod_cgi, 
mod_dir, 
mod_get, 
mod_head, 
mod_log, 
mod_disk_log
]},
{port,8081},
{server_name,"hello_world"},
{server_root,"log"},
{document_root,"www"},
{erl_script_alias, {"/erl", [hello_world]}},
{error_log, "error.log"},
{security_log, "security.log"},
{transfer_log, "transfer.log"},
{mime_types,[
{"html","text/html"},
{"css","text/css"},
{"js","application/x-javascript"},
{"json","application/json"}
]}
]).

service(SessionID, Env, Input) ->
io:write(Env),
io:write(Input),
mod_esi:deliver(SessionID, [
"Content-Type: text/html\r\n\r\n", 
"<html><body>",
"Hello, World!</body></html>"
]).

这是示例代码