mochiweb源码阅读6-request模块常用函数说明
来源:互联网 发布:淘宝自定义属性怎么写 编辑:程序博客网 时间:2024/03/29 06:37
回复客户端函数:
1 Req:respond({Code,ResponseHeaders,Body}) ->response()
2 Req:serve_file(Paht,DocRoot) ->response()
3 Req:ok({ContentType, ResponseHeaders, Body}) ->response()
4 Req:not_found() ->response()
(注:回复客户端函数详细说明可以看前篇mochiweb源码阅读4-概括与使用)
获取http请求信息函数:
1 Req:get(socket) ->Socket 返回Socket
2 Req:get(method) ->’OPTIONS’|’GET’|’HEAD’|’POST’|’PUT’|’DELETE’|’TRACE’ 获取http请求方式
3 Req:get(path) ->string() 返回路径
例:请求连接为localhost:8080/funtest,则path为”funtest”
4 Req:get(raw_path) ->string() 获取原路径
例:请求连接为localhost:8080/funtest,则raw_path为”/funtest”
5 Req:get(version) ->tuple 返回http请求版本 例:{1,1}
6 Req:get(headers) ->dict(). 返回文件头信息
例:浏览器访问本机,连接为localhost:8080/funtest
{7, {"host", {'Host',"localhost:8080"}, {"accept", {'Accept',"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"}, nil, {"accept-language", {'Accept-Language',"en-US,en;q=0.5"}, {"accept-encoding",{'Accept-Encoding',"gzip, deflate"},nil,nil}, {"connection",{'Connection',"keep-alive"},nil,nil}}}, {"user-agent", {'User-Agent',"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0"}, {"upgrade-insecure-requests", {"Upgrade-Insecure-Requests","1"}, nil,nil}, nil}}}
7 Req:get_header_value(Key) ->undefined|string() 获取某个header,如函数6所示,若Key为“User-Agent”则返回“Mozilla…”
8 Req:get(peer) ->string() 返回客户端ip
例如:请求连接为localhost:8080/funtest,则peer=”127.0.0.1”
9 Req:parse_qs() ->[{string(),stringg()}] 获取get参数值
例:请求连接为localhost:8080/funtest?id=5,则返回[“id”,”5”]
10 Req:parse_cookie() ->[{string(),string()}] 解析cookie
- mochiweb源码阅读6-request模块常用函数说明
- mochiweb源码阅读5-函数跳转流程一览
- mochiweb源码阅读1-实例运行
- mochiweb源码阅读2-连接处理
- mochiweb源码阅读3-消息交互
- mochiweb源码阅读4-概括与使用
- [symfony2源码阅读]Request
- mochiweb源码 学习
- highgui模块中常用函数源码
- imgproc模块中常用函数源码
- lua源码阅读(6)-函数
- Python里的OS模块常用函数说明
- Python里的OS模块常用函数说明
- os---Python里的OS模块常用函数说明
- Python里的OS模块常用函数说明
- Python里的OS模块常用函数说明
- Python里的OS模块常用函数说明
- Python里的OS模块常用函数说明
- uboot对Flash和DDR的管理
- 资源编排
- C# this 4种用法
- perl + 匹配前导模式一次或者多次
- 30分钟掌握ES6核心内容(上)
- mochiweb源码阅读6-request模块常用函数说明
- 在web.xml中classpath和classpath*的区别
- JSP指令
- OpenGl实现一个简单的随手画功能
- 安装cocoapods
- java 查找字符串所在的位置
- Java 并发:volatile 关键字解析
- 初入职场,以此纪念
- VC++MFC对话框应用程序实现程序最小化到系统托盘