Newbie question about a web server

I V ivlenin at gmail.com
Tue Aug 21 01:49:01 EDT 2007


On Mon, 20 Aug 2007 00:02:47 -0700, Frank Millman wrote:
> When responding to the POST data received, it sends a 301 response, no
> headers, and then the html page.
[...]
> According to the notes, "You don't have to know much about the HTTP
> protocol at all. Except some basic that when the client request
> something it is a "GET", and when the client sends something it is in
> our case a POST. Some basic responce codes like 200 is OK for GET, and
> 404 is file not found, 301 is OK for a Post."
[...]
> I googled for 'http response code 301', and found that it is actually
> a redirection code. It seems that the notes are misleading.
[...]
> So I guess my questions are -
>   1. what is the correct response for a POST?
>      I think the answer is 200.
>      However, I assume the author is trying to demonstrate a
> particular technique.
>      Can anyone explain what that may be.

The code at that site looks wrong to me; I suspect the original author
was confused about status codes. If you return a 301 redirect code, you
should include a Location: header specifying the URI to redirect to, which
that code doesn't do. Also, if you return a redirect code, you probably
shouldn't include any page content (except perhaps a link to the
redirected page). Note also that 301 is a permanent redirect, that is, it
should be used when the URI has changed permanently (and might cause your
browser to, e.g., update its bookmarks). You're probably not going to use
it in normal operation.

I'm not sure what the author was trying to do, but there is one quite
common case where redirects are used with POST request. When the POST
request does something that you are probably not going to want to repeat,
but you want the resulting page to contain information that the user might
want to refresh, it's common to have the POST return a 302 status (a
temporary redirect). 

One example where this is useful is posting comments to a forum or blog.
Usually, when the comment is posted, you want to return to the list of all
the comments. But the user might refresh that list of comments, and you
don't want their comment to be posted again when they refresh. So you
would have the POST for the comment respond, not with a list of comments,
but with a redirect _to_ the list of comments.



More information about the Python-list mailing list