Utsav
Utsav

Reputation: 566

Redirection using WSGIref

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

Upvotes: 1

Views: 569

Answers (1)

math
math

Reputation: 2881

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.

Upvotes: 2

Related Questions