def get_response(self, raw_request): response = HttpResponse() request = HttpRequest(raw_request) item = None registration = None try: try: self.context = HttpContext(request, response) sPath = request.serverVariables['PATH_INFO'] try: item = db.getItem(sPath) except exceptions.ObjectNotFound: # dir request lstPath = sPath.split('/') dirName = lstPath[1] # remove blank entry & app name to get the requested path sDirPath = '/'.join(lstPath[2:]) webApp = pubdirs.dirs.setdefault(dirName, None) if webApp: registration = webApp.getRegistration( sDirPath, request.serverVariables['REQUEST_METHOD'], request.serverVariables['HTTP_USER_AGENT'], request.getLang()) if not registration: raise exceptions.NotFound, \ 'The resource "%s" does not exist' % sPath # apply pre-processing filters [filter[0].apply(self.context, registration, **filter[1]) for filter in registration.filters if filter[0].type == 'pre'] rtype = registration.type if rtype == 1: # psp page ServerPage.execute(self.context, registration.context) elif rtype == 0: # static file response.loadFromFile(registration.context) if registration.encoding: response.charset = registration.encoding else: # db request if (item == None): raise exceptions.PermissionDenied self.dispatch_method(item) except exceptions.ResponseEnd, e: pass if registration != None: # do we have caching directive? if registration.max_age: response.setExpiration(registration.max_age) # apply post-processing filters [filter[0].apply(self.context, registration, **filter[1]) for filter in registration.filters if filter[0].type == 'post']
def handle_request(self, rh, raw_request=None): if raw_request == None: raw_request = loads(rh.input_buffer) response = HttpResponse() request = HttpRequest(raw_request) item = None registration = None try: try: self.context = HttpContext(request, response) sPath = request.serverVariables['PATH_INFO'] item = _db.get_item(sPath) if item != None and not item._isDeleted: self.context._fetch_session() self.dispatch_method(item) else: # dir request lstPath = sPath.split('/') dirName = lstPath[1] # remove blank entry & app name to get the requested path sDirPath = '/'.join(lstPath[2:]) webApp = pubdirs.dirs.get(dirName, None) if webApp: registration = webApp.getRegistration( sDirPath, request.serverVariables['REQUEST_METHOD'], request.serverVariables['HTTP_USER_AGENT'], request.getLang()) if not registration: raise exceptions.NotFound, \ 'The resource "%s" does not exist' % sPath rtype = registration.type if rtype == 1: # in case of psp fetch session self.context._fetch_session() # apply pre-processing filters [filter[0].apply(self.context, item, registration, **filter[1]) for filter in registration.filters if filter[0].type == 'pre'] if rtype == 1: # psp page ServerPage.execute(self.context, registration.context) elif rtype == 0: # static file f_name = registration.context if_none_match = request.HTTP_IF_NONE_MATCH if if_none_match != None and if_none_match == \ '"%s"' % misc.generate_file_etag(f_name): response._code = 304 else: response.loadFromFile(f_name) response.setHeader('ETag', '"%s"' % misc.generate_file_etag(f_name)) if registration.encoding: response.charset = registration.encoding except exceptions.ResponseEnd, e: pass if registration != None and response._code == 200: # do we have caching directive? if registration.max_age: response.setExpiration(registration.max_age) # apply post-processing filters [filter[0].apply(self.context, item, registration, **filter[1]) for filter in registration.filters if filter[0].type == 'post']