diff options
| author | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-08-31 00:58:07 +0000 |
|---|---|---|
| committer | Diego Nehab <diego@tecgraf.puc-rio.br> | 2003-08-31 00:58:07 +0000 |
| commit | 6789b83ff5c15296267f880d3b98cf8a1800c30a (patch) | |
| tree | 9571dc81cb0147218332cda34b7ccdfed37ddbbc /src/http.lua | |
| parent | c51d4acf1c2a8675a3bb043e799ff4390cef47d6 (diff) | |
| download | luasocket-6789b83ff5c15296267f880d3b98cf8a1800c30a.tar.gz luasocket-6789b83ff5c15296267f880d3b98cf8a1800c30a.tar.bz2 luasocket-6789b83ff5c15296267f880d3b98cf8a1800c30a.zip | |
Starting to use RCS in princeton again. Not behind a firewall anymore.
Diffstat (limited to 'src/http.lua')
| -rw-r--r-- | src/http.lua | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/src/http.lua b/src/http.lua index 212e8f6..252285a 100644 --- a/src/http.lua +++ b/src/http.lua | |||
| @@ -338,16 +338,16 @@ function Private.send_request(sock, method, uri, headers, body_cb) | |||
| 338 | err = Private.try_send(sock, method .. " " .. uri .. " HTTP/1.1\r\n") | 338 | err = Private.try_send(sock, method .. " " .. uri .. " HTTP/1.1\r\n") |
| 339 | if err then return err end | 339 | if err then return err end |
| 340 | -- if there is a request message body, add content-length header | 340 | -- if there is a request message body, add content-length header |
| 341 | if body_cb then | 341 | chunk, size = body_cb() |
| 342 | chunk, size = body_cb() | 342 | if type(chunk) == "string" and type(size) == "number" then |
| 343 | if type(chunk) == "string" and type(size) == "number" then | 343 | if size > 0 then |
| 344 | headers["content-length"] = tostring(size) | 344 | headers["content-length"] = tostring(size) |
| 345 | else | 345 | end |
| 346 | sock:close() | 346 | else |
| 347 | if not chunk and type(size) == "string" then return size | 347 | sock:close() |
| 348 | else return "invalid callback return" end | 348 | if not chunk and type(size) == "string" then return size |
| 349 | end | 349 | else return "invalid callback return" end |
| 350 | end | 350 | end |
| 351 | -- send request headers | 351 | -- send request headers |
| 352 | err = Private.send_headers(sock, headers) | 352 | err = Private.send_headers(sock, headers) |
| 353 | if err then return err end | 353 | if err then return err end |
| @@ -505,7 +505,10 @@ end | |||
| 505 | ----------------------------------------------------------------------------- | 505 | ----------------------------------------------------------------------------- |
| 506 | function Private.build_request(data) | 506 | function Private.build_request(data) |
| 507 | local request = {} | 507 | local request = {} |
| 508 | if type(data) == "table" then for i, v in data do request[i] = v end | 508 | if type(data) == "table" then |
| 509 | for i, v in data | ||
| 510 | do request[i] = v | ||
| 511 | end | ||
| 509 | else request.url = data end | 512 | else request.url = data end |
| 510 | return request | 513 | return request |
| 511 | end | 514 | end |
| @@ -613,18 +616,11 @@ end | |||
| 613 | ----------------------------------------------------------------------------- | 616 | ----------------------------------------------------------------------------- |
| 614 | function Public.request(request) | 617 | function Public.request(request) |
| 615 | local response = {} | 618 | local response = {} |
| 616 | if request.body then | 619 | request.body_cb = socket.callback.send_string(request.body) |
| 617 | request.body_cb = function() | 620 | local concat = socket.concat.create() |
| 618 | return request.body, string.len(request.body) | 621 | response.body_cb = socket.callback.receive_concat(concat) |
| 619 | end | ||
| 620 | end | ||
| 621 | local cat = socket.concat.create() | ||
| 622 | response.body_cb = function(chunk, err) | ||
| 623 | if chunk then cat:addstring(chunk) end | ||
| 624 | return 1 | ||
| 625 | end | ||
| 626 | response = Public.request_cb(request, response) | 622 | response = Public.request_cb(request, response) |
| 627 | response.body = cat:getresult() | 623 | response.body = concat:getresult() |
| 628 | response.body_cb = nil | 624 | response.body_cb = nil |
| 629 | return response | 625 | return response |
| 630 | end | 626 | end |
