diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2001-09-18 20:22:59 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2001-09-18 20:22:59 +0000 |
| commit | 29ab78a74a9ded9b72a757b372c78b454da4c45c (patch) | |
| tree | 072fb3b327d60aad1f624538c586c1aec56882a3 /src | |
| parent | b73a66e635fa2aa5362a389913b98ab86c72f21f (diff) | |
| download | luasocket-29ab78a74a9ded9b72a757b372c78b454da4c45c.tar.gz luasocket-29ab78a74a9ded9b72a757b372c78b454da4c45c.tar.bz2 luasocket-29ab78a74a9ded9b72a757b372c78b454da4c45c.zip | |
HTTP.request was not returning response for body-less requests.
Diffstat (limited to 'src')
| -rw-r--r-- | src/http.lua | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/src/http.lua b/src/http.lua index 1cad3ef..2e8c8e9 100644 --- a/src/http.lua +++ b/src/http.lua | |||
| @@ -156,8 +156,8 @@ function Private.receivebody_bychunks(sock, headers, receive_cb) | |||
| 156 | go, uerr = receive_cb(nil, err) | 156 | go, uerr = receive_cb(nil, err) |
| 157 | return uerr or err | 157 | return uerr or err |
| 158 | end | 158 | end |
| 159 | -- was it the last chunk? | 159 | -- was it the last chunk? |
| 160 | if size <= 0 then break end | 160 | if size <= 0 then break end |
| 161 | -- get chunk | 161 | -- get chunk |
| 162 | chunk, err = %Private.try_receive(sock, size) | 162 | chunk, err = %Private.try_receive(sock, size) |
| 163 | if err then | 163 | if err then |
| @@ -177,14 +177,14 @@ function Private.receivebody_bychunks(sock, headers, receive_cb) | |||
| 177 | return uerr or err | 177 | return uerr or err |
| 178 | end | 178 | end |
| 179 | end | 179 | end |
| 180 | -- the server should not send trailer headers because we didn't send a | 180 | -- the server should not send trailer headers because we didn't send a |
| 181 | -- header informing it we know how to deal with them. we do not risk | 181 | -- header informing it we know how to deal with them. we do not risk |
| 182 | -- being caught unprepaired. | 182 | -- being caught unprepaired. |
| 183 | headers, err = %Private.receive_headers(sock, headers) | 183 | headers, err = %Private.receive_headers(sock, headers) |
| 184 | if err then | 184 | if err then |
| 185 | go, uerr = receive_cb(nil, err) | 185 | go, uerr = receive_cb(nil, err) |
| 186 | return uerr or err | 186 | return uerr or err |
| 187 | end | 187 | end |
| 188 | -- let callback know we are done | 188 | -- let callback know we are done |
| 189 | go, uerr = receive_cb("") | 189 | go, uerr = receive_cb("") |
| 190 | return uerr | 190 | return uerr |
| @@ -257,7 +257,7 @@ end | |||
| 257 | -- nil if successfull or an error message in case of error | 257 | -- nil if successfull or an error message in case of error |
| 258 | ----------------------------------------------------------------------------- | 258 | ----------------------------------------------------------------------------- |
| 259 | function Private.receive_body(sock, headers, receive_cb) | 259 | function Private.receive_body(sock, headers, receive_cb) |
| 260 | local te = headers["transfer-encoding"] | 260 | local te = headers["transfer-encoding"] |
| 261 | if te and te ~= "identity" then | 261 | if te and te ~= "identity" then |
| 262 | -- get by chunked transfer-coding of message body | 262 | -- get by chunked transfer-coding of message body |
| 263 | return %Private.receivebody_bychunks(sock, headers, receive_cb) | 263 | return %Private.receivebody_bychunks(sock, headers, receive_cb) |
| @@ -436,7 +436,7 @@ function Private.authorize(request, parsed, response) | |||
| 436 | request.headers["authorization"] = "Basic " .. | 436 | request.headers["authorization"] = "Basic " .. |
| 437 | Code.base64(parsed.user .. ":" .. parsed.password) | 437 | Code.base64(parsed.user .. ":" .. parsed.password) |
| 438 | local authorize = { | 438 | local authorize = { |
| 439 | redirects = request.redirects, | 439 | redirects = request.redirects, |
| 440 | method = request.method, | 440 | method = request.method, |
| 441 | url = request.url, | 441 | url = request.url, |
| 442 | body_cb = request.body_cb, | 442 | body_cb = request.body_cb, |
| @@ -540,10 +540,10 @@ end | |||
| 540 | ----------------------------------------------------------------------------- | 540 | ----------------------------------------------------------------------------- |
| 541 | function Public.request_cb(request, response) | 541 | function Public.request_cb(request, response) |
| 542 | local parsed = URL.parse_url(request.url, { | 542 | local parsed = URL.parse_url(request.url, { |
| 543 | host = "", | 543 | host = "", |
| 544 | port = %Public.PORT, | 544 | port = %Public.PORT, |
| 545 | path ="/" | 545 | path ="/" |
| 546 | }) | 546 | }) |
| 547 | -- explicit authentication info overrides that given by the URL | 547 | -- explicit authentication info overrides that given by the URL |
| 548 | parsed.user = request.user or parsed.user | 548 | parsed.user = request.user or parsed.user |
| 549 | parsed.password = request.password or parsed.password | 549 | parsed.password = request.password or parsed.password |
| @@ -585,6 +585,7 @@ function Public.request_cb(request, response) | |||
| 585 | return response | 585 | return response |
| 586 | end | 586 | end |
| 587 | sock:close() | 587 | sock:close() |
| 588 | return response | ||
| 588 | end | 589 | end |
| 589 | 590 | ||
| 590 | ----------------------------------------------------------------------------- | 591 | ----------------------------------------------------------------------------- |
| @@ -637,8 +638,8 @@ end | |||
| 637 | -- error: error message if any | 638 | -- error: error message if any |
| 638 | ----------------------------------------------------------------------------- | 639 | ----------------------------------------------------------------------------- |
| 639 | function Public.get(url_or_request) | 640 | function Public.get(url_or_request) |
| 640 | local request = %Private.build_request(url_or_request) | 641 | local request = %Private.build_request(url_or_request) |
| 641 | request.method = "GET" | 642 | request.method = "GET" |
| 642 | local response = %Public.request(request) | 643 | local response = %Public.request(request) |
| 643 | return response.body, response.headers, | 644 | return response.body, response.headers, |
| 644 | response.code, response.error | 645 | response.code, response.error |
| @@ -660,9 +661,9 @@ end | |||
| 660 | -- error: error message, or nil if successfull | 661 | -- error: error message, or nil if successfull |
| 661 | ----------------------------------------------------------------------------- | 662 | ----------------------------------------------------------------------------- |
| 662 | function Public.post(url_or_request, body) | 663 | function Public.post(url_or_request, body) |
| 663 | local request = %Private.build_request(url_or_request) | 664 | local request = %Private.build_request(url_or_request) |
| 664 | request.method = "POST" | 665 | request.method = "POST" |
| 665 | request.body = request.body or body | 666 | request.body = request.body or body |
| 666 | local response = %Public.request(request) | 667 | local response = %Public.request(request) |
| 667 | return response.body, response.headers, | 668 | return response.body, response.headers, |
| 668 | response.code, response.error | 669 | response.code, response.error |
