Mercurial > prosody-hg
comparison net/http.lua @ 2807:8e2dba8904a7
net.http: Port commit 2f235c57d713 to net.http to fix headers in responses (thanks dersd)
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 19 Feb 2010 02:58:34 +0000 |
| parents | a0ea72846b46 |
| children | 23bb7e29819e |
comparison
equal
deleted
inserted
replaced
| 2806:6efc430c6e10 | 2807:8e2dba8904a7 |
|---|---|
| 71 end | 71 end |
| 72 end | 72 end |
| 73 elseif request.state == "headers" then | 73 elseif request.state == "headers" then |
| 74 print("Reading headers...") | 74 print("Reading headers...") |
| 75 local pos = startpos; | 75 local pos = startpos; |
| 76 local headers = request.responseheaders or {}; | 76 local headers, headers_complete = request.responseheaders; |
| 77 if not headers then | |
| 78 headers = {}; | |
| 79 request.responseheaders = headers; | |
| 80 end | |
| 77 for line in data:sub(startpos, -1):gmatch("(.-)\r\n") do | 81 for line in data:sub(startpos, -1):gmatch("(.-)\r\n") do |
| 78 startpos = startpos + #line + 2; | 82 startpos = startpos + #line + 2; |
| 79 local k, v = line:match("(%S+): (.+)"); | 83 local k, v = line:match("(%S+): (.+)"); |
| 80 if k and v then | 84 if k and v then |
| 81 headers[k:lower()] = v; | 85 headers[k:lower()] = v; |
| 82 print("Header: "..k:lower().." = "..v); | 86 --print("Header: "..k:lower().." = "..v); |
| 83 elseif #line == 0 then | 87 elseif #line == 0 then |
| 84 request.responseheaders = headers; | 88 headers_complete = true; |
| 85 break; | 89 break; |
| 86 else | 90 else |
| 87 print("Unhandled header line: "..line); | 91 print("Unhandled header line: "..line); |
| 88 end | 92 end |
| 89 end | 93 end |
| 94 if not headers_complete then return; end | |
| 90 -- Reached the end of the headers | 95 -- Reached the end of the headers |
| 91 request.state = "body"; | 96 if not expectbody(request, request.code) then |
| 97 request.callback(nil, request.code, request); | |
| 98 return; | |
| 99 end | |
| 100 request.state = "body"; | |
| 92 if #data > startpos then | 101 if #data > startpos then |
| 93 return request_reader(request, data, startpos); | 102 return request_reader(request, data, startpos); |
| 94 end | 103 end |
| 95 elseif request.state == "status" then | 104 elseif request.state == "status" then |
| 96 print("Reading status...") | 105 print("Reading status...") |
| 100 return request.callback("invalid-status-line", 0, request); | 109 return request.callback("invalid-status-line", 0, request); |
| 101 end | 110 end |
| 102 | 111 |
| 103 request.code, request.responseversion = code, http; | 112 request.code, request.responseversion = code, http; |
| 104 | 113 |
| 105 if request.onlystatus or not expectbody(request, code) then | 114 if request.onlystatus then |
| 106 if request.callback then | 115 if request.callback then |
| 107 request.callback(nil, code, request); | 116 request.callback(nil, code, request); |
| 108 end | 117 end |
| 109 destroy_request(request); | 118 destroy_request(request); |
| 110 return; | 119 return; |
