ogcserver: Add content-length to cgi, wsgi, and mod-python handlers and max_age to wsgi and mod_python - thanks tmcw, closes #251
This commit is contained in:
parent
44aa40a610
commit
ea2e39b81b
3 changed files with 19 additions and 4 deletions
|
@ -84,6 +84,7 @@ class Handler(cgi.DebugHandler):
|
|||
raise OGCException('Operation "%s" not supported.' % request, 'OperationNotSupported')
|
||||
response = requesthandler(ogcparams)
|
||||
req.set_header('Content-Type', response.content_type)
|
||||
req.set_header('Content-Length', str(len(response.content))
|
||||
req.write(response.content)
|
||||
|
||||
def traceback(self, req):
|
||||
|
@ -99,6 +100,7 @@ class Handler(cgi.DebugHandler):
|
|||
eh = ExceptionHandler111(self.debug)
|
||||
response = eh.getresponse(reqparams)
|
||||
req.set_header('Content-Type', response.content_type)
|
||||
req.set_header('Content-Length', str(len(response.content))
|
||||
req.write(response.content)
|
||||
|
||||
def lowerparams(params):
|
||||
|
|
|
@ -47,6 +47,10 @@ class ModHandler(object):
|
|||
self.debug = int(conf.get('server', 'debug'))
|
||||
else:
|
||||
self.debug = 0
|
||||
if self.conf.has_option_with_value('server', 'maxage'):
|
||||
self.max_age = 'max-age=%d' % self.conf.get('server', 'maxage')
|
||||
else:
|
||||
self.max_age = None
|
||||
|
||||
def __call__(self, apacheReq):
|
||||
try:
|
||||
|
@ -95,6 +99,9 @@ class ModHandler(object):
|
|||
except Exception, E:
|
||||
return self.traceback(apacheReq,E)
|
||||
|
||||
if self.max_age:
|
||||
apacheReq.headers_out.add('Cache-Control', max_age)
|
||||
apacheReq.headers_out.add('Content-Length', str(len(response.content)))
|
||||
apacheReq.send_http_header()
|
||||
apacheReq.write(response.content)
|
||||
return apache.OK
|
||||
|
@ -112,8 +119,7 @@ class ModHandler(object):
|
|||
eh = ExceptionHandler111(self.debug)
|
||||
response = eh.getresponse(reqparams)
|
||||
apacheReq.content_type = response.content_type
|
||||
#apacheReq.status = apache.HTTP_NOT_FOUND
|
||||
#apacheReq.status = apache.HTTP_INTERNAL_SERVER_ERROR
|
||||
apacheReq.headers_out.add('Content-Length', str(len(response.content)))
|
||||
apacheReq.send_http_header()
|
||||
apacheReq.write(response.content)
|
||||
return apache.OK
|
||||
|
@ -122,4 +128,4 @@ def lowerparams(params):
|
|||
reqparams = {}
|
||||
for key, value in params.items():
|
||||
reqparams[key.lower()] = value
|
||||
return reqparams
|
||||
return reqparams
|
||||
|
|
|
@ -46,6 +46,10 @@ class WSGIApp:
|
|||
self.debug = int(conf.get('server', 'debug'))
|
||||
else:
|
||||
self.debug = 0
|
||||
if self.conf.has_option_with_value('server', 'maxage'):
|
||||
self.max_age = 'max-age=%d' % self.conf.get('server', 'maxage')
|
||||
else:
|
||||
self.max_age = None
|
||||
|
||||
def __call__(self, environ, start_response):
|
||||
reqparams = {}
|
||||
|
@ -92,6 +96,9 @@ class WSGIApp:
|
|||
else:
|
||||
eh = ExceptionHandler111(self.debug)
|
||||
response = eh.getresponse(reqparams)
|
||||
start_response('200 OK', [('Content-Type', response.content_type)])
|
||||
response_headers = [('Content-Type', response.content_type),('Content-Length', str(len(response.content)))]
|
||||
if self.max_age:
|
||||
response_headers.append(('Cache-Control', max_age))
|
||||
start_response('200 OK', response_headers)
|
||||
yield response.content
|
||||
|
Loading…
Add table
Reference in a new issue