diff options
| author | Diego Nehab <diego@impa.br> | 2016-03-07 01:30:30 -0300 |
|---|---|---|
| committer | Diego Nehab <diego@impa.br> | 2016-03-07 01:30:30 -0300 |
| commit | 916b548240b1513410b13f964d80f329aec9c13a (patch) | |
| tree | dee1cfd05ca7ad72a3db2673fbc7ce005098bb2a /src/http.lua | |
| parent | 5b4b9158799293eeaf8439d40a7845b5b0a5e125 (diff) | |
| download | luasocket-916b548240b1513410b13f964d80f329aec9c13a.tar.gz luasocket-916b548240b1513410b13f964d80f329aec9c13a.tar.bz2 luasocket-916b548240b1513410b13f964d80f329aec9c13a.zip | |
Family agostic FTP and expose HTTP/FTP url parsing
Diffstat (limited to 'src/http.lua')
| -rw-r--r-- | src/http.lua | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/http.lua b/src/http.lua index d6bcc91..f2fff01 100644 --- a/src/http.lua +++ b/src/http.lua | |||
| @@ -346,11 +346,13 @@ end | |||
| 346 | return 1, code, headers, status | 346 | return 1, code, headers, status |
| 347 | end | 347 | end |
| 348 | 348 | ||
| 349 | local function srequest(u, b) | 349 | -- turns an url and a body into a generic request |
| 350 | local function genericform(u, b) | ||
| 350 | local t = {} | 351 | local t = {} |
| 351 | local reqt = { | 352 | local reqt = { |
| 352 | url = u, | 353 | url = u, |
| 353 | sink = ltn12.sink.table(t) | 354 | sink = ltn12.sink.table(t), |
| 355 | target = t | ||
| 354 | } | 356 | } |
| 355 | if b then | 357 | if b then |
| 356 | reqt.source = ltn12.source.string(b) | 358 | reqt.source = ltn12.source.string(b) |
| @@ -360,8 +362,15 @@ local function srequest(u, b) | |||
| 360 | } | 362 | } |
| 361 | reqt.method = "POST" | 363 | reqt.method = "POST" |
| 362 | end | 364 | end |
| 363 | local code, headers, status = socket.skip(1, trequest(reqt)) | 365 | return reqt |
| 364 | return table.concat(t), code, headers, status | 366 | end |
| 367 | |||
| 368 | _M.genericform = genericform | ||
| 369 | |||
| 370 | local function srequest(u, b) | ||
| 371 | local reqt = genericform(u, b) | ||
| 372 | local _, code, headers, status = trequest(reqt) | ||
| 373 | return table.concat(reqt.target), code, headers, status | ||
| 365 | end | 374 | end |
| 366 | 375 | ||
| 367 | _M.request = socket.protect(function(reqt, body) | 376 | _M.request = socket.protect(function(reqt, body) |
