Mercurial > prosody-hg
comparison net/http.lua @ 7463:3b6e7ce9431f
net.http: Add request.id to every request object (can be overridden by providing ex.id)
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 07 Jul 2016 23:07:19 +0100 |
| parents | 3b07f38d70f5 |
| children | 3b7de72e58a9 |
comparison
equal
deleted
inserted
replaced
| 7461:72e48bddf617 | 7463:3b6e7ce9431f |
|---|---|
| 24 local log = require "util.logger".init("http"); | 24 local log = require "util.logger".init("http"); |
| 25 | 25 |
| 26 local _ENV = nil; | 26 local _ENV = nil; |
| 27 | 27 |
| 28 local requests = {}; -- Open requests | 28 local requests = {}; -- Open requests |
| 29 | |
| 30 local function make_id(req) return (tostring(req):match("%x+$")); end | |
| 29 | 31 |
| 30 local listener = { default_port = 80, default_mode = "*a" }; | 32 local listener = { default_port = 80, default_mode = "*a" }; |
| 31 | 33 |
| 32 function listener.onconnect(conn) | 34 function listener.onconnect(conn) |
| 33 local req = requests[conn]; | 35 local req = requests[conn]; |
| 122 end | 124 end |
| 123 | 125 |
| 124 if not req.path then | 126 if not req.path then |
| 125 req.path = "/"; | 127 req.path = "/"; |
| 126 end | 128 end |
| 129 | |
| 130 req.id = ex and ex.id or make_id(req); | |
| 127 | 131 |
| 128 local method, headers, body; | 132 local method, headers, body; |
| 129 | 133 |
| 130 local host, port = req.host, req.port; | 134 local host, port = req.host, req.port; |
| 131 local host_header = host; | 135 local host_header = host; |
