Software /
code /
prosody
Comparison
net/http/server.lua @ 4713:9c15fa5192d3
net.http.server: Fire http-error 400 if request fails sanity checks
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 26 Apr 2012 16:11:08 +0100 |
parent | 4710:54ca6511e699 |
child | 4715:4d6ebe54671e |
comparison
equal
deleted
inserted
replaced
4712:4fc99f1b7570 | 4713:9c15fa5192d3 |
---|---|
168 send = _M.send_response; | 168 send = _M.send_response; |
169 finish_cb = finish_cb; | 169 finish_cb = finish_cb; |
170 }; | 170 }; |
171 conn._http_open_response = response; | 171 conn._http_open_response = response; |
172 | 172 |
173 local err; | |
173 if not request.headers.host then | 174 if not request.headers.host then |
175 err = "No 'Host' header"; | |
176 elseif not request.path then | |
177 err = "Invalid path"; | |
178 end | |
179 | |
180 if err then | |
174 response.status_code = 400; | 181 response.status_code = 400; |
175 response.headers.content_type = "text/html"; | 182 response.headers.content_type = "text/html"; |
176 response:send(events.fire_event("http-error", { code = 400, message = "No 'Host' header" })); | 183 response:send(events.fire_event("http-error", { code = 400, message = err })); |
177 else | 184 else |
178 local host = request.headers.host; | 185 local host = request.headers.host; |
179 if host then | 186 if host then |
180 host = host:match("[^:]*"):lower(); | 187 host = host:match("[^:]*"):lower(); |
181 local event = request.method.." "..host..request.path:match("[^?]*"); | 188 local event = request.method.." "..host..request.path:match("[^?]*"); |