feat: identify the client in the User-Agent - #15
Open
jayakishore709 wants to merge 3 commits into
Open
Conversation
- send `datastreamr/<version> httr2/<version>` on every request - add `setUserAgent()` to prepend the caller's own product, validated as an RFC 9110 token so it cannot inject headers - fall back to an unversioned identifier when the sources are read with source() rather than installed - add unit tests, bump to 2.1.0
The image copied only R/*.R, so the working directory was not a package and every test failed with `object 'locations' not found` -- 8 failures, 0 passes against the documented command. - copy DESCRIPTION and NAMESPACE so pkgload::load_all() can load the package - load_all() in the documented test commands - install R packages from the base image's binary repository instead of naming a source repo, which forced every dependency to compile - drop devtools and the system libraries only its dependencies needed - filter test_dir() by file name so new test files are picked up
`Id` is not a filterable field on /Metadata, so the integration test failed with a 400 from schema validation. The mocked unit test passed only because the mock never validates the query. DOI is already covered in both suites.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requests from this package are indistinguishable from any other
httr2caller in our access logs, which is a large share of public API traffic. This adds an identifier and lets callers name their own application, matching what datastream-py anddatastreamjsnow do.Changes
setUserAgent(name, version = NULL)— new exported function. Every request already carriesdatastreamr/2.1.0 httr2/1.2.1; this prepends the caller's product:The datastreamr identifier is always kept, repeat calls replace rather than accumulate, and call order relative to
setAPIKey()does not matter. The name is validated as an RFC 9110 product token, so a caller-supplied value cannot inject additional headers.Docker test harness fix (second commit) — the image copied only
R/*.R, so the working directory was not a package and the documented test command failed 8 tests, 0 passes withobject 'locations' not found. This predates the change here; confirmed by running the documented command againstmain. Fixed by copyingDESCRIPTION/NAMESPACE, callingpkgload::load_all()in the documented commands, and installing from the base image's binary repository rather than a source repo — the old build was still compilingstringiafter 9½ minutes.Dropped the metadata
Idfilter tests (third commit) —Idis not a filterable field on/Metadata, so the integration test failed with a 400 from schema validation, and the mocked unit test passed only because the mock never validates the query.DOIis already covered in both suites.Version
2.0.1→2.1.0.Verification
Run in Docker (R 4.4.1):
[ FAIL 0 | PASS 42 ]a/1/2,(comment)) — all raise, UA left unchangedAccept/Accept-Encoding/x-api-keyall still sentsource()withoutDESCRIPTION) degrades todatastreamr httr2/1.2.1instead of erroringroxygen2::roxygenise()reproduces the committedNAMESPACE/manexactly$count, locations by DOI, and observations byLocationIdall return correct data with the composed UA reaching the edge logs[ FAIL 0 | PASS 36 ]Notes
r-curl/libcurlversions are omitted from the UA because reading them requires acurl::call andcurlis not inImports— not worth a new dependency.