0

I am working on a toy web framework and I have implemented a method redirect_to for redirecting the user to a specified URL. Here the code

def _redirect_to(_self, _url):
  """Takes an url as argument and returns a location header"""

  return ([('Location', _url)], "")                   # --- (i)

The returned tuple is then handled by the app, here's the code

...
else:                                                             
  status = '200 OK'                                               
  params['_GET'] = get_data(_environment)                         
  params['_POST'] = post_data(_environment)                       
  (headers, response) = objview(objcontroller, _params = params)  # tuple from (i) is stored here

_start_response(status, headers)

However it is not working. Here are the headers that my browser is receiving:

Content-Length:0
Date:Thu, 19 Jul 2012 06:03:52 GMT
Location:http://google.com
Server:WSGIServer/0.1 Python/2.7.3

Is there something wrong with the headers ??

Cheers,

Utsav

Utsav
  • 536
  • 2
  • 6
  • 18
  • What is the status code of your redirect reply? If it's 200 as shown in the code above, this is wrong. Redirection is done with the 'Location' header **and** a 302 (Found) status code. – math Jul 19 '12 at 07:47

1 Answers1

1

To do a HTTP redirection, you need both:

  • 'Location' HTTP header
  • '302 Found' HTTP status code

It seems that you are not changing the HTTP status code from 200 to 302.

math
  • 2,811
  • 3
  • 24
  • 29