1
클라이언트의 http 헤더에 api-key를 추가하기 위해 NET : HTTP 젬을 사용하려고하는데, 시험 할 때 어떤 이유로 작동하지 않는 것 같습니다. 그것 out.Basically 서버는 클라이언트의 HTTP 헤더 또는 아무것도 요청을 제공하기 위해 http_x_api 헤더가 필요합니다. 당신이 env['HTTP_API_KEY']
를 확인해야하므로NET : HTTP 헤더 루비 보석
서버 코드를 서버에서
require 'sinatra'
before do
halt 400 if (env['API_KEY']) != 'wow'
end
get '/' do
"boo"
end
클라이언트 코드
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