-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Since `req_url_relative()` is a more general interface. And improve `req_url()` docs, links, and examples. Part of #625
- Loading branch information
Showing
30 changed files
with
290 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#' Modify URL path | ||
#' | ||
#' @description | ||
#' `r lifecycle::badge("deprecated")` | ||
#' | ||
#' * `req_url_path()` modifies the path. | ||
#' * `req_url_path_append()` adds to the path. | ||
#' | ||
#' Please use [req_url_relative()] instead. | ||
#' | ||
#' @inheritParams req_perform | ||
#' @param ... For `req_url_path()` and `req_url_path_append()`: A sequence of | ||
#' path components that will be combined with `/`. | ||
#' @returns A modified HTTP [request]. | ||
#' @export | ||
#' @examples | ||
#' req <- request("http://example.com/a/b/c") | ||
#' | ||
#' # OLD | ||
#' req |> req_url_path("/d/e/f") | ||
#' req |> req_url_path_append("d/e/f") | ||
#' | ||
#' # NEW | ||
#' req |> req_url_relative("/d/e/f") | ||
#' req |> req_url_relative("d/e/f") | ||
req_url_path <- function(req, ...) { | ||
lifecycle::deprecate_soft("1.1.0", "req_url_path()", "req_url_relative()") | ||
|
||
check_request(req) | ||
path <- dots_to_path(...) | ||
|
||
req_url(req, url_modify(req$url, path = path)) | ||
} | ||
|
||
#' @export | ||
#' @rdname req_url_path | ||
req_url_path_append <- function(req, ...) { | ||
lifecycle::deprecate_soft("1.1.0", "req_url_path_append()", "req_url_relative()") | ||
|
||
check_request(req) | ||
path <- dots_to_path(...) | ||
|
||
url <- url_parse(req$url) | ||
url$path <- paste0(sub("/$", "", url$path), path) | ||
|
||
req_url(req, url_build(url)) | ||
} | ||
|
||
dots_to_path <- function(...) { | ||
path <- paste(c(...), collapse = "/") | ||
# Ensure we don't add duplicate /s | ||
# NB: also keeps "" unchanged. | ||
sub("^([^/])", "/\\1", path) | ||
} |
Oops, something went wrong.