Do not convert headers to a hash#14
Merged
Merged
Conversation
Instead make use of whatever mechanism the existing libraries provider to access a single header by name, regardless of the notation. This also changes how `rack` response headers are handled. This should now more closely resemble request headers.
oneiros
commented
May 20, 2025
Comment on lines
+62
to
+66
| signature_headers = {} | ||
| %w[signature-input signature].each do |name| | ||
| value = message.header(name) | ||
| signature_headers[name] = value if value | ||
| end |
Contributor
Author
There was a problem hiding this comment.
Not having a full hash means we lose the convenience of Hash#slice. I do not think this is a huge problem, but I dislike having to repeat this in the rack auth middleware.
The only alternative I could come up with, was passing the full Linzer::Message object to Signature.build. Not sure if that is something you would consider. But maybe you have another idea?
Owner
|
Thanks for fixing this issue! 😀 |
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.
This is my attempt to fix #13
This removes access to a full hash of headers from a
Message(and adapter) and instead allows requesting a single header value. To access this, the internal mechanisms ofhttpandnet-httpare being used, so the notation (e.g.Signature-Inputvs.signature-input) does not matter.rackis a bit more complicated, but thankfully the necessary conversion methods already existed.While attempting to refactor this, I noticed a discrepancy between how headers for
rackrequests and responses are handled. And indeed,rackstores headers for requests and responses quite differently. But this comment here leads me to believe, that it expects the same notation (e.g.HTTP_SIGNATURE_INPUTinstead of justsignature-input). I have not looked into this too closely, but judging from that comment and how some accessor methods in that class work, I believe that should be correct.So I tried to fix this as well.
Of course this is not the only way to address the problem in #13. So if you have a different and/or better idea, feel free to discard this.