moonbridge
diff moonbridge_http.lua @ 68:ad06fc76906a
Extended io.poll(...) to check FILE buffers; Replaced method "readuntil" with "xread"
author | jbe |
---|---|
date | Sat Apr 04 17:19:12 2015 +0200 (2015-04-04) |
parents | 3d1f23f1dbc6 |
children | 0ec070d6f5d9 |
line diff
1.1 --- a/moonbridge_http.lua Sat Apr 04 11:42:34 2015 +0200 1.2 +++ b/moonbridge_http.lua Sat Apr 04 17:19:12 2015 +0200 1.3 @@ -833,7 +833,7 @@ 1.4 end 1.5 if request.headers_flags["Transfer-Encoding"]["chunked"] then 1.6 while true do 1.7 - local line = socket:readuntil("\n", 32 + remaining_body_size_limit) 1.8 + local line = socket:xread(32 + remaining_body_size_limit, "\n") 1.9 if not line then 1.10 request_error(true, "400 Bad Request", "Unexpected EOF while reading next chunk of request body") 1.11 end 1.12 @@ -854,13 +854,13 @@ 1.13 end 1.14 if len == 0 then break end 1.15 read_body_bytes(len, callback) 1.16 - local term = socket:readuntil("\n", 2) 1.17 + local term = socket:xread(2, "\n") 1.18 if term ~= "\r\n" and term ~= "\n" then 1.19 request_error(true, "400 Bad Request", "Encoding error while reading chunk of request body") 1.20 end 1.21 end 1.22 while true do 1.23 - local line = socket:readuntil("\n", 2 + remaining_body_size_limit) 1.24 + local line = socket:xread(2 + remaining_body_size_limit, "\n") 1.25 if line == "\r\n" or line == "\n" then break end 1.26 remaining_body_size_limit = remaining_body_size_limit - #line 1.27 if remaining_body_size_limit < 0 then 1.28 @@ -895,15 +895,13 @@ 1.29 end 1.30 }) 1.31 -- wait for input: 1.32 - if not socket.input:pending() then 1.33 - if not io.poll({socket.input}, nil, request_idle_timeout) then 1.34 - return request_error(false, "408 Request Timeout") 1.35 - end 1.36 + if not io.poll({socket.input}, nil, request_idle_timeout) then 1.37 + return request_error(false, "408 Request Timeout") 1.38 end 1.39 -- set timeout for request header processing: 1.40 timeout(request_header_timeout) 1.41 -- read and parse request line: 1.42 - local line = socket:readuntil("\n", remaining_header_size_limit) 1.43 + local line = socket:xread(remaining_header_size_limit, "\n") 1.44 if not line then return survive end 1.45 remaining_header_size_limit = remaining_header_size_limit - #line 1.46 if remaining_header_size_limit == 0 then 1.47 @@ -919,7 +917,7 @@ 1.48 end 1.49 -- read and parse headers: 1.50 while true do 1.51 - local line = socket:readuntil("\n", remaining_header_size_limit); 1.52 + local line = socket:xread(remaining_header_size_limit, "\n"); 1.53 remaining_header_size_limit = remaining_header_size_limit - #line 1.54 if not line then 1.55 return request_error(false, "400 Bad Request")