Hi All
I have a simple Sinatra proxy, which when an endpoint is called, will redirect to another endpoint on the same Sinatra proxy.
When I make a request with a header, the proxy doesn't seem to pass this header through to the second endpoint when the request redirects in the first. This is my code:
get '/first' do
# get the header from the request
username = env['HTTP_USERNAME']
# set the header for the response
response['username'] = username
redirect '/second'
end
get '/second' do
# This doesn't exist when redirected from /first
puts env['HTTP_USERNAME']
# Here is a list of all headers
env.each_key do |key|
puts "KEY: #{key} VALUE: #{env[key]}" unless key.nil?
end
"DONE"
end
Any tips would be greatly appreciated.
Thanks
-
That is intentionally.
redirecttriggers an HTTP redirect, a new request will be fired. Also, passing onenvvalues is done via modifyingenv, notresponse.The main question is, what do you mean by header? Request header or response header? From your example I figure you mean request header, therefore
response['username'] = usernameshould berequest.env['username'] = username. You could then replaceredirect '/second'withrequest.path_info = '/second'; passto do some sort of internal redirect. If you don't pass the value on to another Rack middleware/endpoint, you could also store the user name in an instance variable.get '/first' do request.path_info = '/second' pass end get '/second' do puts request.env['HTTP_USERNAME'] "DONE" endemson : Thanks Konstantin - that was just what I was looking for. I clean forgot I could use the pass method. Cheers.
0 comments:
Post a Comment