Skip to content

feat: identify the client in the User-Agent - #15

Open
jayakishore709 wants to merge 3 commits into
mainfrom
feat/user-agent
Open

feat: identify the client in the User-Agent#15
jayakishore709 wants to merge 3 commits into
mainfrom
feat/user-agent

Conversation

@jayakishore709

@jayakishore709 jayakishore709 commented Jul 30, 2026

Copy link
Copy Markdown

Requests from this package are indistinguishable from any other httr2 caller 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 and datastreamjs now do.

Changes

setUserAgent(name, version = NULL) — new exported function. Every request already carries datastreamr/2.1.0 httr2/1.2.1; this prepends the caller's product:

setUserAgent('MyProject', '1.0')
# User-Agent: MyProject/1.0 datastreamr/2.1.0 httr2/1.2.1

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 with object 'locations' not found. This predates the change here; confirmed by running the documented command against main. Fixed by copying DESCRIPTION/NAMESPACE, calling pkgload::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 compiling stringi after 9½ minutes.

Dropped the metadata Id filter tests (third commit) — Id is 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. DOI is already covered in both suites.

Version 2.0.12.1.0.

Verification

Run in Docker (R 4.4.1):

  • Unit tests: [ FAIL 0 | PASS 42 ]
  • UA composition: default, caller product, optional version, repeat-call replacement
  • 6 rejected inputs (space, CRLF, embedded newline, empty, a/1/2, (comment)) — all raise, UA left unchanged
  • Accept / Accept-Encoding / x-api-key all still sent
  • Sourced-not-installed path (source() without DESCRIPTION) degrades to datastreamr httr2/1.2.1 instead of erroring
  • roxygen2::roxygenise() reproduces the committed NAMESPACE/man exactly
  • Live against the development API: metadata, $count, locations by DOI, and observations by LocationId all return correct data with the composed UA reaching the edge logs
  • Integration tests against production: [ FAIL 0 | PASS 36 ]

Notes

  • r-curl/libcurl versions are omitted from the UA because reading them requires a curl:: call and curl is not in Imports — not worth a new dependency.

- 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.
@jayakishore709
jayakishore709 requested a review from meghanDS July 30, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant