[mod_python] Problems with headers in proxy handler

Graham Dumpleton grahamd at dscpl.com.au
Sat Dec 10 15:58:19 EST 2005


On 10/12/2005, at 10:51 PM, Sebastjan Trepca wrote:

> Ok :) Just didn't want to import whole module because of a constant.

The module is already resident in memory because it contains a lot of
stuff which mod_python itself uses. When you import it, it is just a  
quick
lookup of sys.modules by Python internals to get it and it doesn't have
to go back to disk. Even this quick lookup only happens once, it isn't
like CGI where everything is loaded on each request.

> Btw, what is the difference between OK and DONE? I understand that
> DONE will stop Apache to go processing further, but where further can
> it go? I mean what is processed after the request handler ?

If DONE is used in content handler phase, it may well be not much
different than OK (not sure), but it will be if used in earlier  
phases such
as access handler, auth handler, fixup handler etc.

> Sebastjan
>
> On 10/12/05, Graham Dumpleton <grahamd at dscpl.com.au> wrote:
>
>> Which version of mod_python are you using?
>>
>> On 08/12/2005, at 12:14 AM, Sebastjan Trepca wrote:
>>
>>
>>> Hi,
>>>
>>> I'm writing a proxy handler which makes a request to a different  
>>> page
>>> and retrieves its content and headers. This is the source:
>>>
>>> import urllib2
>>> from mod_python import util
>>>
>>> def handler(req):
>>>     req.headers_out.clear()
>>>     f = util.FieldStorage(req)
>>>     url = f.get('url',None)
>>>     if(url):
>>>         url=url.split('?')
>>>         if(len(url)>1):
>>>             u = url[0]
>>>             p = url[1]
>>>             ureq = urllib2.Request(u,p)
>>>         else:
>>>             u = url[0]
>>>             ureq = urllib2.Request(u)
>>>         for h in req.headers_in:
>>>             ureq.add_header(h,req.headers_in[h])
>>>         r = urllib2.urlopen(ureq)
>>>         for h in r.headers:
>>>             req.headers_out[h]=r.headers[h]
>>>         data =     r.read()
>>>
>>
>> In case you are using mod_python 2.7.X, add at this point:
>>
>>             req.send_http_header()
>>
>>
>>>         req.write(data)
>>>         return 0#-2 doesn't help either
>>>     return 0
>>>
>>
>> Will not make a difference, but don't return 0/2, use apache.OK/
>> apache.DONE
>> instead. Using literal integer values is bad programming practice.
>>
>>
>>> But this seems to have problems with headers, I get back basic  
>>> headers
>>> from my Apache server, which is wrong of course.
>>> Any ideas why is this happening?
>>>
>>
>> Graham
>>
>



More information about the Mod_python mailing list