How to set http header in HTTP::Server.response

Hi,
I can set the header with code like this:

server = HTTP::Server.new() do |c|
    c.response.content_type="application/json"
    c.response.headers.add "Access-Control-Allow-Origin","*"
    c.response.print api_parser.find_api(c.request.path)
end

but this one doesn’t work:

h = HTTP::Headers.new() 
h.add "Access-Control-Allow-Origin","*"
   server = HTTP::Server.new() do |c|
     c.response.content_type="application/json"
     c.response.headers.add h
     c.response.print api_parser.find_api(c.request.path)
end

How can I add predefined HTTP::Header to HTTP:Response?
Thanks

There’s a HTTP::Headers#merge! :)

1 Like

Thanks.