Skip to content

Do not convert headers to a hash#14

Merged
nomadium merged 2 commits into
nomadium:masterfrom
oneiros:fix_header_access
May 21, 2025
Merged

Do not convert headers to a hash#14
nomadium merged 2 commits into
nomadium:masterfrom
oneiros:fix_header_access

Conversation

@oneiros

@oneiros oneiros commented May 20, 2025

Copy link
Copy Markdown
Contributor

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 of http and net-http are being used, so the notation (e.g. Signature-Input vs. signature-input) does not matter. rack is 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 rack requests and responses are handled. And indeed, rack stores 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_INPUT instead of just signature-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.

oneiros added 2 commits May 20, 2025 16:25
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.
Comment thread lib/linzer.rb
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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@nomadium
nomadium merged commit 57cce8a into nomadium:master May 21, 2025
@nomadium

nomadium commented May 21, 2025

Copy link
Copy Markdown
Owner

Thanks for fixing this issue! 😀
I just cut a new stable release including these changes.

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.

Accessing headers in http adapter classes fails

2 participants