diff options
Diffstat (limited to 'src/http.lua')
| -rw-r--r-- | src/http.lua | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/http.lua b/src/http.lua index fb13d99..72bde0a 100644 --- a/src/http.lua +++ b/src/http.lua | |||
| @@ -421,7 +421,7 @@ end | |||
| 421 | ----------------------------------------------------------------------------- | 421 | ----------------------------------------------------------------------------- |
| 422 | local function authorize(reqt, parsed, respt) | 422 | local function authorize(reqt, parsed, respt) |
| 423 | reqt.headers["authorization"] = "Basic " .. | 423 | reqt.headers["authorization"] = "Basic " .. |
| 424 | (socket.code.b64(parsed.user .. ":" .. parsed.password)) | 424 | (socket.mime.b64(parsed.user .. ":" .. parsed.password)) |
| 425 | local autht = { | 425 | local autht = { |
| 426 | nredirects = reqt.nredirects, | 426 | nredirects = reqt.nredirects, |
| 427 | method = reqt.method, | 427 | method = reqt.method, |
| @@ -429,8 +429,8 @@ local function authorize(reqt, parsed, respt) | |||
| 429 | body_cb = reqt.body_cb, | 429 | body_cb = reqt.body_cb, |
| 430 | headers = reqt.headers, | 430 | headers = reqt.headers, |
| 431 | timeout = reqt.timeout, | 431 | timeout = reqt.timeout, |
| 432 | host = reqt.host, | 432 | proxyhost = reqt.proxyhost, |
| 433 | port = reqt.port | 433 | proxyport = reqt.proxyport |
| 434 | } | 434 | } |
| 435 | return request_cb(autht, respt) | 435 | return request_cb(autht, respt) |
| 436 | end | 436 | end |
| @@ -471,8 +471,8 @@ local function redirect(reqt, respt) | |||
| 471 | body_cb = reqt.body_cb, | 471 | body_cb = reqt.body_cb, |
| 472 | headers = reqt.headers, | 472 | headers = reqt.headers, |
| 473 | timeout = reqt.timeout, | 473 | timeout = reqt.timeout, |
| 474 | host = reqt.host, | 474 | proxyhost = reqt.proxyhost, |
| 475 | port = reqt.port | 475 | proxyport = reqt.proxyport |
| 476 | } | 476 | } |
| 477 | respt = request_cb(redirt, respt) | 477 | respt = request_cb(redirt, respt) |
| 478 | -- we pass the location header as a clue we tried to redirect | 478 | -- we pass the location header as a clue we tried to redirect |
| @@ -482,8 +482,8 @@ end | |||
| 482 | 482 | ||
| 483 | ----------------------------------------------------------------------------- | 483 | ----------------------------------------------------------------------------- |
| 484 | -- Computes the request URI from the parsed request URL | 484 | -- Computes the request URI from the parsed request URL |
| 485 | -- If host and port are given in the request table, we use he | 485 | -- If we are using a proxy, we use the absoluteURI format. |
| 486 | -- absoluteURI format. Otherwise, we use the abs_path format. | 486 | -- Otherwise, we use the abs_path format. |
| 487 | -- Input | 487 | -- Input |
| 488 | -- parsed: parsed URL | 488 | -- parsed: parsed URL |
| 489 | -- Returns | 489 | -- Returns |
| @@ -491,7 +491,7 @@ end | |||
| 491 | ----------------------------------------------------------------------------- | 491 | ----------------------------------------------------------------------------- |
| 492 | local function request_uri(reqt, parsed) | 492 | local function request_uri(reqt, parsed) |
| 493 | local url | 493 | local url |
| 494 | if not reqt.host and not reqt.port then | 494 | if not reqt.proxyhost and not reqt.proxyport then |
| 495 | url = { | 495 | url = { |
| 496 | path = parsed.path, | 496 | path = parsed.path, |
| 497 | params = parsed.params, | 497 | params = parsed.params, |
| @@ -543,6 +543,7 @@ end | |||
| 543 | -- error: error message, or nil if successfull | 543 | -- error: error message, or nil if successfull |
| 544 | ----------------------------------------------------------------------------- | 544 | ----------------------------------------------------------------------------- |
| 545 | function request_cb(reqt, respt) | 545 | function request_cb(reqt, respt) |
| 546 | local sock, ret | ||
| 546 | local parsed = socket.url.parse(reqt.url, { | 547 | local parsed = socket.url.parse(reqt.url, { |
| 547 | host = "", | 548 | host = "", |
| 548 | port = PORT, | 549 | port = PORT, |
| @@ -561,14 +562,14 @@ function request_cb(reqt, respt) | |||
| 561 | -- fill default headers | 562 | -- fill default headers |
| 562 | reqt.headers = fill_headers(reqt.headers, parsed) | 563 | reqt.headers = fill_headers(reqt.headers, parsed) |
| 563 | -- try to connect to server | 564 | -- try to connect to server |
| 564 | local sock | ||
| 565 | sock, respt.error = socket.tcp() | 565 | sock, respt.error = socket.tcp() |
| 566 | if not sock then return respt end | 566 | if not sock then return respt end |
| 567 | -- set connection timeout so that we do not hang forever | 567 | -- set connection timeout so that we do not hang forever |
| 568 | sock:settimeout(reqt.timeout or TIMEOUT) | 568 | sock:settimeout(reqt.timeout or TIMEOUT) |
| 569 | local ret | 569 | ret, respt.error = sock:connect( |
| 570 | ret, respt.error = sock:connect(reqt.host or parsed.host, | 570 | reqt.proxyhost or PROXYHOST or parsed.host, |
| 571 | reqt.port or parsed.port) | 571 | reqt.proxyport or PROXYPORT or parsed.port |
| 572 | ) | ||
| 572 | if not ret then | 573 | if not ret then |
| 573 | sock:close() | 574 | sock:close() |
| 574 | return respt | 575 | return respt |
