From d70487a60fc2f5cea525ab0b8ea3392a05669ff3 Mon Sep 17 00:00:00 2001 From: Yunuuuu Date: Sat, 29 Mar 2025 23:18:58 +0800 Subject: [PATCH 1/2] add proxy support --- R/gh.R | 35 ++++++++++++++++++++++++++++++++--- R/gh_request.R | 4 +++- man/gh.Rd | 12 ++++++++++++ 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/R/gh.R b/R/gh.R index 995eff2..db074b6 100644 --- a/R/gh.R +++ b/R/gh.R @@ -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_paassword 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. @@ -165,6 +169,11 @@ gh <- function(endpoint, .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, @@ -183,7 +192,17 @@ gh <- function(endpoint, 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 + ) + } req <- gh_build_request( endpoint = endpoint, params = params, @@ -195,7 +214,8 @@ gh <- function(endpoint, 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) @@ -292,7 +312,16 @@ gh_make_request <- function(x, error_call = caller_env()) { 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 + ) + } if (!isFALSE(getOption("gh_cache"))) { req <- httr2::req_cache( req, diff --git a/R/gh_request.R b/R/gh_request.R index 70cebca..2362563 100644 --- a/R/gh_request.R +++ b/R/gh_request.R @@ -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, diff --git a/man/gh.Rd b/man/gh.Rd index 15d1e08..d429d45 100644 --- a/man/gh.Rd +++ b/man/gh.Rd @@ -14,6 +14,11 @@ gh( .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, @@ -70,6 +75,13 @@ environment variable if set.} \item{.method}{HTTP method to use if not explicitly supplied in the \code{endpoint}.} +\item{.proxy_url, .proxy_port}{Location of proxy.} + +\item{.proxy_username, .proxy_paassword}{Login details for proxy, if needed.} + +\item{.proxy_auth}{Type of HTTP authentication to use. Should be one of the +following: \code{basic}, \code{digest}, \code{digest_ie}, \code{gssnegotiate}, \code{ntlm}, \code{any}.} + \item{.limit}{Number of records to return. This can be used instead of manual pagination. By default it is \code{NULL}, which means that the defaults of the GitHub API are used. From 2c65faedd58119a2bcacbd8055542f1ddb65bdf6 Mon Sep 17 00:00:00 2001 From: Yunuuuu Date: Sat, 29 Mar 2025 23:26:55 +0800 Subject: [PATCH 2/2] fix docs --- R/gh.R | 2 +- man/gh.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/gh.R b/R/gh.R index db074b6..486c937 100644 --- a/R/gh.R +++ b/R/gh.R @@ -47,7 +47,7 @@ #' @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_paassword Login details for proxy, if needed. +#' @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 diff --git a/man/gh.Rd b/man/gh.Rd index d429d45..3a18744 100644 --- a/man/gh.Rd +++ b/man/gh.Rd @@ -77,7 +77,7 @@ environment variable if set.} \item{.proxy_url, .proxy_port}{Location of proxy.} -\item{.proxy_username, .proxy_paassword}{Login details for proxy, if needed.} +\item{.proxy_username, .proxy_password}{Login details for proxy, if needed.} \item{.proxy_auth}{Type of HTTP authentication to use. Should be one of the following: \code{basic}, \code{digest}, \code{digest_ie}, \code{gssnegotiate}, \code{ntlm}, \code{any}.}