Skip to content

Commit

Permalink
Add an option to close HTTP connections instead of reusing them (#432)
Browse files Browse the repository at this point in the history
* Add an option to close HTTP connections instead of reusing them.
* Add `new_http_request` parameter documentation.
  • Loading branch information
davidkretch authored Aug 6, 2021
1 parent 6b89ff5 commit e70532e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions paws.common/R/client.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Config <- struct(
enforce_should_retry_check = FALSE,
region = "",
disable_ssl = FALSE,
close_connection = FALSE,
max_retries = -1,
timeout = 60,
retryer = NULL,
Expand Down
12 changes: 11 additions & 1 deletion paws.common/R/net.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ HttpResponse <- struct(
)

# Returns an HTTP request given a method, URL, and an optional body.
new_http_request <- function(method, url, body = NULL, timeout = NULL) {
#
# @param method The HTTP method to use for the request.
# @param url The URL to send the request to.
# @param body The body to send in the request, in bytes.
# @param close Whether to immediately close the connection, or else reuse connections.
# @param timeout How long to wait for an initial response.
new_http_request <- function(method, url, body = NULL, close = FALSE, timeout = NULL) {
if (method == "") {
method <- "GET"
}
Expand All @@ -64,6 +70,7 @@ new_http_request <- function(method, url, body = NULL, timeout = NULL) {
header = list(), # TODO
body = body,
host = u$host,
close = close,
timeout = timeout
)
return(req)
Expand All @@ -89,6 +96,9 @@ issue <- function(http_request) {
method <- http_request$method
url <- build_url(http_request$url)
headers <- unlist(http_request$header)
if (http_request$close) {
headers["Connection"] <- "close"
}
body <- http_request$body
timeout <- httr::config(connecttimeout = http_request$timeout)
if (is.null(http_request$timeout)) timeout <- NULL
Expand Down
8 changes: 7 additions & 1 deletion paws.common/R/request.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ new_request <- function(client, operation, params, data) {
method <- "POST"
}

http_req <- new_http_request(method, "", NULL, client$config$timeout)
http_req <- new_http_request(
method = method,
url = "",
body = NULL,
close = client$config$close_connection,
timeout = client$config$timeout
)

http_req$url <- parse_url(
paste0(client$client_info$endpoint, operation$http_path)
Expand Down

0 comments on commit e70532e

Please sign in to comment.