Mine is one way to do it, but I recommend doing it as @yfeldblum recommends, simply short-circuit downcase
for the header keys that need to have their case left-alone.
In multiple places in Net::HTTP::HTTPHeader the headers get folded to lower-case using downcase
.
I think it is pretty drastic to change that behavior, but this will do it. Add this to your source and it will redefine the methods in the HTTPHeader module that had downcase
in them.
module HTTPHeader
def initialize_http_header(initheader)
@header = {}
return unless initheader
initheader.each do |key, value|
warn "net/http: warning: duplicated HTTP header: #{key}" if key?(key) and $VERBOSE
@header[key] = [value.strip]
end
end
def [](key)
a = @header[key] or return nil
a.join(', ')
end
def []=(key, val)
unless val
@header.delete key
return val
end
@header[key] = [val]
end
def add_field(key, val)
if @header.key?(key)
@header[key].push val
else
@header[key] = [val]
end
end
def get_fields(key)
return nil unless @header[key]
@header[key].dup
end
def fetch(key, *args, &block) #:yield: +key+
a = @header.fetch(key, *args, &block)
a.kind_of?(Array) ? a.join(', ') : a
end
# Removes a header field.
def delete(key)
@header.delete(key)
end
# true if +key+ header exists.
def key?(key)
@header.key?(key)
end
def tokens(vals)
return [] unless vals
vals.map {|v| v.split(',') }.flatten\
.reject {|str| str.strip.empty? }\
.map {|tok| tok.strip }
end
end
I think this is a brute force way of going about it, but nothing else more elegant jumped to mind.
While this should fix the problem for any Ruby libraries using Net::HTTP, it will probably fail for any gems that use Curl or libcurl.