gsub_response {httptest2}R Documentation

Find and replace within a response object

Description

This function passes its arguments to base::gsub() in order to find and replace string patterns (regular expressions) within the URL and the response body of httr2_response objects.

Usage

gsub_response(response, pattern, replacement, ...)

Arguments

response

An httr2_response or http2_request object to sanitize.

pattern

From base::gsub(): "character string containing a regular expression (or character string for fixed = TRUE) to be matched in the given character vector." Passed to gsub(). See the docs for gsub() for further details.

replacement

A replacement for the matched pattern, possibly including regular expression backreferences. Passed to gsub(). See the docs for gsub() for further details.

...

Additional logical arguments passed to gsub(): ignore.case, perl, fixed, and useBytes are the possible options.

Details

Note that, unlike gsub(), the first argument of the function is response, not pattern, while the equivalent argument in gsub(), "x", is placed third. This difference is to maintain consistency with the other redactor functions in httptest2, which all take response as the first argument.

This function also can be applied to an http2_request object to replace patterns inside the request URL.

Value

An httr2_response object, same as was passed in, with the pattern replaced in the URLs and bodies.


[Package httptest2 version 1.1.0 Index]