Skip to content

add proxy support #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions R/gh.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
#' environment variable if set.
#' @param .method HTTP method to use if not explicitly supplied in the
#' `endpoint`.
#' @param .proxy_url,.proxy_port Location of proxy.
#' @param .proxy_username,.proxy_password Login details for proxy, if needed.
#' @param .proxy_auth Type of HTTP authentication to use. Should be one of the
#' following: `basic`, `digest`, `digest_ie`, `gssnegotiate`, `ntlm`, `any`.
#' @param .limit Number of records to return. This can be used
#' instead of manual pagination. By default it is `NULL`,
#' which means that the defaults of the GitHub API are used.
Expand Down Expand Up @@ -165,6 +169,11 @@
.overwrite = FALSE,
.api_url = NULL,
.method = "GET",
.proxy_url = NULL,
.proxy_port = NULL,
.proxy_username = NULL,
.proxy_password = NULL,
.proxy_auth = "basic",
.limit = NULL,
.accept = "application/vnd.github.v3+json",
.send_headers = NULL,
Expand All @@ -183,7 +192,17 @@
if (!is.null(per_page)) {
params <- c(params, list(per_page = per_page))
}

if (is.null(.proxy_url)) {
proxy <- NULL
} else {
proxy <- list(
url = .proxy_url,
port = .proxy_port,
username = .proxy_username,
password = .proxy_password,
auth = .proxy_auth
)

Check warning on line 204 in R/gh.R

View check run for this annotation

Codecov / codecov/patch

R/gh.R#L198-L204

Added lines #L198 - L204 were not covered by tests
}
req <- gh_build_request(
endpoint = endpoint,
params = params,
Expand All @@ -195,7 +214,8 @@
max_wait = .max_wait,
max_rate = .max_rate,
api_url = .api_url,
method = .method
method = .method,
proxy = proxy
)

if (req$method == "GET") check_named_nas(params)
Expand Down Expand Up @@ -292,7 +312,16 @@
if (Sys.getenv("GH_FORCE_HTTP_1_1") == "true") {
req <- httr2::req_options(req, http_version = 2)
}

if (!is.null(x$proxy)) {
req <- httr2::req_proxy(
req,
url = x$proxy$url,
port = x$proxy$port,
username = x$proxy$username,
password = x$proxy$password,
auth = x$proxy$auth
)

Check warning on line 323 in R/gh.R

View check run for this annotation

Codecov / codecov/patch

R/gh.R#L316-L323

Added lines #L316 - L323 were not covered by tests
}
if (!isFALSE(getOption("gh_cache"))) {
req <- httr2::req_cache(
req,
Expand Down
4 changes: 3 additions & 1 deletion R/gh_request.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ gh_build_request <- function(endpoint = "/user",
max_wait = 10,
max_rate = NULL,
api_url = NULL,
method = "GET") {
method = "GET",
proxy = NULL) {
working <- list(
method = method,
proxy = proxy,
url = character(),
headers = NULL,
query = NULL,
Expand Down
12 changes: 12 additions & 0 deletions man/gh.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.