Skip to content

Don't serialize redacted headers#742

Merged
hadley merged 3 commits into
mainfrom
header-redact-weakref
Jun 19, 2025
Merged

Don't serialize redacted headers#742
hadley merged 3 commits into
mainfrom
header-redact-weakref

Conversation

@hadley
Copy link
Copy Markdown
Member

@hadley hadley commented Jun 17, 2025

This required quite a lot of refactoring to clarify what's actually going on. It should now be clearer that there is a redacted sentinel value which is used to nicely format, print, and str redacted values that might be exposed to the user (I don't fully recall why I added this but I suspect it's because we only want to apply cli formatting at the exact time when the value is displayed). This code now lives in utils-redacted.R.

I also clarified the type of the headers object — the componets can either be an atomic vector or a weakref. And since redacted components now have their own type, we no longer need the redact attribute.

Fixes #721

This required quite a lot of refactoring to clarify what's actually going on. It should now be clearer that there is a redacted sentinel value which is used to nicely format, print, and str redacted values that might be exposed to the user (I don't fully recall why I added this but I suspect it's because we only want to apply cli formatting at the exact time when the value is displayed). This code now lives in `utils-redacted.R`.

I also clarified the type of the headers object — the componets can either be an atomic vector or a weakref. And since redacted components now have their own type, we no longer need the `redact` attribute.

Fixes #721
@shikokuchuo
Copy link
Copy Markdown
Member

Practically there's no way to access the 'value' from the 'key' if the weakref itself is no longer around, hence it's probably fine that you tie the lifetime of 'value' to the package the environment.

However, if you want to ensure the lifetime of 'value' is really tied to a single request, then you could instead pass the request req as an argument to as_header() and consuming functions, and you'd then be able to use req$state as the 'key'.

And test `req_dry_run()` changes
@hadley
Copy link
Copy Markdown
Member Author

hadley commented Jun 18, 2025

I decided to make the lifespan a bit more explicit and I do think it makes it clearer.

@hadley hadley merged commit f52f4b9 into main Jun 19, 2025
13 checks passed
@hadley hadley deleted the header-redact-weakref branch June 19, 2025 21:49
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.

Make redacted field more robust

2 participants