Skip to content
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

Supporting adding request headers to fload #60

Merged
merged 4 commits into from
Dec 9, 2020
Merged
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
14 changes: 14 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
2020-12-07 Dirk Eddelbuettel <edd@debian.org>

* R/fload.R (fload): Use ... instead of explicit header argument
* R/utils.R (.prep_input): Support ... use
* man/fparse.Rd: Document ... use

2020-12-04 Dirk Eddelbuettel <edd@debian.org>

* DESCRIPTION (Version, Date): Roll version and date

* R/fload.R (fload): Additional argument 'headers' to pass API headers
* R/utils.R (.prep_input): Idem, passes 'headers' on to curl
* man/fparse.Rd: Document option

2020-11-01 Dirk Eddelbuettel <edd@debian.org>

* DESCRIPTION (Version, Date): Release 0.1.3
Expand Down
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: RcppSimdJson
Type: Package
Title: 'Rcpp' Bindings for the 'simdjson' Header-Only Library for 'JSON' Parsing
Version: 0.1.3
Version: 0.1.3.1
Date: 2020-11-01
Author: Dirk Eddelbuettel, Brendan Knapp
Maintainer: Dirk Eddelbuettel <edd@debian.org>
Expand All @@ -19,3 +19,4 @@ Suggests: bit64, tinytest
URL: https://github.com/eddelbuettel/rcppsimdjson/
BugReports: https://github.com/eddelbuettel/rcppsimdjson/issues
RoxygenNote: 7.1.1
Encoding: UTF-8
8 changes: 6 additions & 2 deletions R/fload.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#' @param compressed_download Whether to request server-side compression on
#' the downloaded document, default: \code{FALSE}
#'
#' @param ... Optional arguments which can be use \emph{e.g.} to pass additional
#' header settings
#'
#' @examples
#' # load JSON files ===========================================================
Expand Down Expand Up @@ -64,7 +66,8 @@ fload <- function(json,
verbose = FALSE,
temp_dir = tempdir(),
keep_temp_files = FALSE,
compressed_download = FALSE) {
compressed_download = FALSE,
...) {
# validate arguments =======================================================
if (!.is_valid_json_arg(json)) {
stop("`json=` must be a non-empty character vector, raw vector, or a list containing raw vectors.")
Expand Down Expand Up @@ -157,7 +160,8 @@ fload <- function(json,
diagnosis <- .prep_input(json,
temp_dir = temp_dir,
compressed_download = compressed_download,
verbose = verbose)
verbose = verbose,
...)
if (!keep_temp_files) {
on.exit(unlink(diagnosis$input[diagnosis$is_from_url]), add = TRUE)
}
Expand Down
12 changes: 7 additions & 5 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
.prep_input <- function(input,
temp_dir,
compressed_download,
verbose) {
verbose,
headers = NULL,
...) {
input[!is.na(input)] <- path.expand(input[!is.na(input)])
diagnosis <- .diagnose_input(input)
.headers <- headers

if (length(missing_files <- diagnosis$input[!is.na(diagnosis$input) &
!diagnosis$is_from_url &
Expand All @@ -28,14 +31,13 @@
}

if (any(diagnosis$is_from_url)) {
if (compressed_download) {
.headers <- c(`Accept-Encoding` = "gzip")
if (compressed_download) { # #nocov start
.headers <- c(.headers, `Accept-Encoding` = "gzip")
# for local files, don't attach .gz
.fileext <- rep(NA_character_, nrow(diagnosis))
.fileext[diagnosis$is_local_file_url] <- diagnosis$file_ext[diagnosis$is_local_file_url]
.fileext[diagnosis$is_remote_file_url] <- sprintf("%s.gz", diagnosis$file_ext[diagnosis$is_remote_file_url])
} else {
.headers <- NULL
} else { # #nocov end
.fileext <- diagnosis$file_ext[diagnosis$is_from_url]
}

Expand Down
6 changes: 5 additions & 1 deletion man/fparse.Rd

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

4 changes: 2 additions & 2 deletions man/simdjson-utilities.Rd

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