Skip to content

Instantly share code, notes, and snippets.

@NotGrm
Created June 6, 2024 09:26
Show Gist options
  • Save NotGrm/1e0a12e8e12a736ea58fa58ff802a1a7 to your computer and use it in GitHub Desktop.
Save NotGrm/1e0a12e8e12a736ea58fa58ff802a1a7 to your computer and use it in GitHub Desktop.
# A case-sensitive header key, this is a workaroung for Net::HTTP's
# capitalizing headers as the standard allow any case for headers.
#
# But sometimes we have to works with some API providers whose backend servers
# do not follow standards
CaseSensitiveHeader = Data.define(:key) do
def split(*)
key.split(*).map { |k| self.class.new(k) }
end
def capitalize = key
def downcase = self
def to_s = self
end
# Usage
HTTParty.get('url', headers: { CaseSensitiveHeader['x-sensitive-header'] => 'value' })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment