Skip to content

Commit

Permalink
Set user agent for HTTP requests (#58)
Browse files Browse the repository at this point in the history
* Set user agent

* Fix and redocument

* I don't know why this is working now

* Add NEWS item
  • Loading branch information
mikemahoney218 authored Mar 29, 2024
1 parent 7c2e83b commit 5d05feb
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Depends:
Imports:
future.apply,
glue,
httr,
jsonlite,
lifecycle,
proceduralnames,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ export(sign_planetary_computer)
export(spectral_indices)
export(spectral_indices_url)
export(stack_rasters)
importFrom(httr,user_agent)
importFrom(rlang,"%||%")
importFrom(stats,predict)
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@

* `get_stac_data()` now warns if `asset_names` is `NULL` and there is more
than one asset per item.

* Functions sending HTTP requests now set a user agent of
`rsi (https://permian-global-research.github.io/rsi/)`

# rsi 0.1.2

Expand Down
1 change: 1 addition & 0 deletions R/0-globals.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rsi_user_agent <- httr::user_agent("rsi (https://permian-global-research.github.io/rsi/)")
3 changes: 2 additions & 1 deletion R/download.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ rsi_download_rasters <- function(items,
GDAL_DISABLE_READDIR_ON_OPEN = "EMPTY_DIR",
GDAL_HTTP_VERSION = "2",
GDAL_HTTP_MERGE_CONSECUTIVE_RANGES = "YES",
GDAL_NUM_THREADS = "ALL_CPUS"
GDAL_NUM_THREADS = "ALL_CPUS",
GDAL_HTTP_USERAGENT = "rsi (https://permian-global-research.github.io/rsi/)"
),
...) {
if (!inherits(aoi, "bbox")) aoi <- sf::st_bbox(aoi)
Expand Down
3 changes: 2 additions & 1 deletion R/get_stac_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,8 @@ get_stac_data <- function(aoi,
GDAL_DISABLE_READDIR_ON_OPEN = "EMPTY_DIR",
GDAL_HTTP_VERSION = "2",
GDAL_HTTP_MERGE_CONSECUTIVE_RANGES = "YES",
GDAL_NUM_THREADS = "ALL_CPUS"
GDAL_NUM_THREADS = "ALL_CPUS",
GDAL_HTTP_USERAGENT = "rsi (https://permian-global-research.github.io/rsi/)"
)) {
# query |> filter |> download |> mask |> composite |> rescale
if (!(inherits(aoi, "sf") || inherits(aoi, "sfc"))) {
Expand Down
8 changes: 6 additions & 2 deletions R/query_and_sign.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ rsi_query_api <- function(bbox,
limit = limit
)

items <- rstac::items_fetch(rstac::get_request(items))
items <- rstac::items_fetch(
rstac::get_request(items, rsi_user_agent),
rsi_user_agent
)

items
}
Expand Down Expand Up @@ -96,11 +99,12 @@ rsi_query_api <- function(bbox,
sign_planetary_computer <- function(items,
subscription_key = Sys.getenv("rsi_pc_key")) {
if (subscription_key == "") {
rstac::items_sign(items, rstac::sign_planetary_computer())
rstac::items_sign(items, rstac::sign_planetary_computer(rsi_user_agent))
} else {
rstac::items_sign(
items,
rstac::sign_planetary_computer(
rsi_user_agent,
headers = c("Ocp-Apim-Subscription-Key" = subscription_key)
)
)
Expand Down
1 change: 1 addition & 0 deletions R/rsi-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ NULL

#' @importFrom rlang %||%
#' @importFrom stats predict
#' @importFrom httr user_agent

utils::globalVariables(c(
"dem_band_mapping",
Expand Down
3 changes: 2 additions & 1 deletion man/get_stac_data.Rd

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

3 changes: 2 additions & 1 deletion man/rsi_download_rasters.Rd

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

0 comments on commit 5d05feb

Please sign in to comment.