NET:HTTP headers ruby gem

I am trying to use the NET:HTTP gem to add an api-key to http header of
a client, but it just doesn’t seem to be working for some reason when I
try and test it out.Basically the server requires the http header of the
client or anything to have http_x_api header in order to serve the
request.

Server code

require ‘sinatra’

before do
halt 400 if (env[‘API_KEY’]) != ‘wow’
end

get ‘/’ do
“boo”
end

client code
require ‘net/http’
require ‘uri’

port = ENV['PORT'] || '7474'

res = Net::HTTP.start('localhost', port )  { |h| h.get('/')}
res.add_field('api-key', 'wow')
res.each_header do |key, value|
  p "#{key} => #{value}"
end
puts (res.code == '200' && res.body == 'boo') ? 'OK' : 'FAIL'

this the response i get back :=>

“x-frame-options => sameorigin”
“x-xss-protection => 1; mode=block”
“content-type => text/html;charset=utf-8”
“content-length => 0”
“connection => keep-alive”
“server => thin 1.5.0 codename Knife”
“api-key => wow”
FAIL

On Oct 4, 2012, at 23:43 , Shaban K. [email protected] wrote:

I am trying to use the NET:HTTP gem to add an api-key to http header of
a client, but it just doesn’t seem to be working for some reason when I
try and test it out.Basically the server requires the http header of the
client or anything to have http_x_api header in order to serve the
request.

By “to http header of a client” I assume you mean to the request…

res = Net::HTTP.start(‘localhost’, port ) { |h| h.get(‘/’)}

^^^ response                                     ^^^^^^^^^^ request

and everything below is response as well…

Yeah that is what I mean