cgi.FieldStorage and REDIRECT_REQUEST_METHOD

A

Austyn Bontrager

Should cgi.FieldStorage examine the environment variable
REDIRECT_REQUEST_METHOD before examining REQUEST_METHOD?

I'm running Apache, and write my CGI scripts in Python.
I have this in a /techdocs/.htaccess file:

ErrorDocument 401 /forms/registration.cgi
Require valid-user


The registration script contains a <form method="POST">, so it submits
back to itself.

So a typical conversation goes like this:
> GET /techdocs/usermanual.pdf HTTP/1.1

< HTTP/1.1 401 Unauthorized

(browser pops up login box and user types something in username field)
> GET /techdocs/usermanual.pdf HTTP/1.1
> Authorization: Basic YWFhYTo=

< HTTP/1.1 200 OK
> POST /techdocs/usermanual.pdf HTTP/1.1
> Authorization: Basic YWFhYTo=
> Content-Type: application/x-www-form-urlencoded
> username=joe&[email protected]

< HTTP/1.1 200 OK
< <html><body>Thanks for registering. Log in as "joe" to
< <a href="">Download</a> the file.</body></html>

(user clicks on that Download link)
> GET /techdocs/usermanual.pdf HTTP/1.1
> Authorization: Basic YWFhYTo=

< HTTP/1.1 200 OK
< Content-type: application/x-pdf
< ...


So after the POST, in my script I'd expect env variable REQUEST_METHOD
to be "POST". However, REQUEST_METHOD is "GET", and
REDIRECT_REQUEST_METHOD is "POST", and cgi.FieldStorage can't find the
form values.

I'm working around it by putting at the top of my script:
RRM = "REDIRECT_REQUEST_METHOD"
if os.environ.get(RRM)
os.environ["REQUEST_METHOD"] = os.environ.get(RRM)


Any better ideas? Should this be added to the cgi module (I think it's
specific to Apache)? Should I ask this question somewhere else?

Thanks
Austyn
 
L

Lee Harr

Should cgi.FieldStorage examine the environment variable
REDIRECT_REQUEST_METHOD before examining REQUEST_METHOD?

I'm running Apache, and write my CGI scripts in Python.
I have this in a /techdocs/.htaccess file:

ErrorDocument 401 /forms/registration.cgi
Require valid-user


The registration script contains a <form method="POST">, so it submits
back to itself.

So a typical conversation goes like this:
GET /techdocs/usermanual.pdf HTTP/1.1

< HTTP/1.1 401 Unauthorized

(browser pops up login box and user types something in username field)
GET /techdocs/usermanual.pdf HTTP/1.1
Authorization: Basic YWFhYTo=

< HTTP/1.1 200 OK
POST /techdocs/usermanual.pdf HTTP/1.1
Authorization: Basic YWFhYTo=
Content-Type: application/x-www-form-urlencoded
username=joe&[email protected]

< HTTP/1.1 200 OK
< <html><body>Thanks for registering. Log in as "joe" to
< <a href="">Download</a> the file.</body></html>

(user clicks on that Download link)
GET /techdocs/usermanual.pdf HTTP/1.1
Authorization: Basic YWFhYTo=

< HTTP/1.1 200 OK
< Content-type: application/x-pdf
< ...


So after the POST, in my script I'd expect env variable REQUEST_METHOD
to be "POST". However, REQUEST_METHOD is "GET", and
REDIRECT_REQUEST_METHOD is "POST", and cgi.FieldStorage can't find the
form values.

I'm working around it by putting at the top of my script:
RRM = "REDIRECT_REQUEST_METHOD"
if os.environ.get(RRM)
os.environ["REQUEST_METHOD"] = os.environ.get(RRM)


Any better ideas? Should this be added to the cgi module (I think it's
specific to Apache)? Should I ask this question somewhere else?


You might try here:
http://python.org/sigs/web-sig/
http://mail.python.org/mailman/listinfo/web-sig

or if you are pretty sure this is an apache only thing try:
http://httpd.apache.org/lists.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top