def match (self, request): # make sure the command is GET, HEAD, or POST: if request.command not in self.valid_commands: return 0 path, params, query, fragment = request.split_uri() if '%' in path: path = unquote (path) request.angel_action = None if len(path) > 1: # strip off all leading slashes while path and path[0] == '/': path = path[1:] if path: parts = path.split('/') if len(parts) == 3 and parts[0] == 'action': request.angel_action = (parts[1:], params, query, fragment) return 1 elif (len(parts)==4 and parts[0] == 'action' and parts[3][0:3]=='seq'): note(2, "in match with 4 parts, parts = %s", str(parts)) request.angel_action = (parts[1:3], params, query, fragment) return 1 elif (len(parts) > 3) and (parts[0] == 'action') and (is_hierarchical_extension(parts[1])): # to support extensions with hierarchical static elements, like GWT-generated UIs note(4, "hierarchical request, parts = %s", str(parts)) request.angel_action = ((parts[1], '/'.join(parts[2:])), params, query, fragment) return 1 else: # This case occurs when the browser requests that an image # be downloaded. In that case parts look like: # parts = ['docs', '01070-41-2044-555', 'thumbnails', '1.png'] pass elif path == '/': request.angel_action = (TOP_LEVEL_ACTION, params, query, fragment) return 1 return 0
def handle_request (self, request): [path, params, query, fragment] = request.split_uri() while path and path[0] == '/': path = path[1:] if '%' in path: path = unquote (path) env = {} env['REQUEST_URI'] = "/" + path env['REQUEST_METHOD'] = string.upper(request.command) env['SERVER_PORT'] = str(request.channel.server.port) env['SERVER_NAME'] = request.channel.server.server_name env['SERVER_SOFTWARE'] = request['Server'] env['DOCUMENT_ROOT'] = self.document_root parts = string.split(path, "/") # are script_name and path_info ok? env['SCRIPT_NAME'] = "/" + parts[0] if query and query[0] == "?": query = query[1:] env['QUERY_STRING'] = query try: path_info = "/" + string.join(parts[1:], "/") except: path_info = '' env['PATH_INFO'] = path_info env['GATEWAY_INTERFACE']='CGI/1.1' # what should this really be? env['REMOTE_ADDR'] =request.channel.addr[0] env['REMOTE_HOST'] =request.channel.addr[0] # TODO: connect to resolver for header in request.header: [key,value]=string.split(header,": ",1) key=string.lower(key) if header2env.has_key(key): if header2env[key]: env[header2env[key]]=value else: key = 'HTTP_' + string.upper( string.join( string.split (key,"-"), "_" ) ) env[key]=value ## remove empty environment variables for key in env.keys(): if env[key]=="" or env[key]==None: del env[key] try: httphost = env['HTTP_HOST'] parts = string.split(httphost,":") env['HTTP_HOST'] = parts[0] except KeyError: pass if request.command in ('put', 'post'): # PUT data requires a correct Content-Length: header # (though I bet with http/1.1 we can expect chunked encoding) request.collector = collector (self, request, env) request.channel.set_terminator (None) else: sin = StringIO.StringIO ('') self.continue_request (sin, request, env)
def get_environment(self, request, # These are strictly performance hackery... h2ehas=header2env.has_key, h2eget=header2env.get, workdir=os.getcwd(), ospath=os.path, ): (path, params, query, fragment) = request.split_uri() if params: path = path + params # undo medusa bug! while path and path[0] == '/': path = path[1:] if '%' in path: path = unquote(path) if query: # ZPublisher doesn't want the leading '?' query = query[1:] server=request.channel.server env = {} env['REQUEST_METHOD']=request.command.upper() env['SERVER_PORT']=str(server.port) env['SERVER_NAME']=server.request_server_name env['SERVER_SOFTWARE']=server.SERVER_IDENT env['SERVER_PROTOCOL']="HTTP/"+request.version env['channel.creation_time']=request.channel.creation_time if self.uri_base=='/': env['SCRIPT_NAME']='' env['PATH_INFO']='/' + path else: env['SCRIPT_NAME'] = self.uri_base try: path_info=path.split(self.uri_base[1:],1)[1] except: path_info='' env['PATH_INFO']=path_info env['PATH_TRANSLATED']=ospath.normpath(ospath.join( workdir, env['PATH_INFO'])) if query: env['QUERY_STRING'] = query env['GATEWAY_INTERFACE']='CGI/1.1' env['REMOTE_ADDR']=request.channel.addr[0] # This is a really bad hack to support WebDAV # clients accessing documents through GET # on the HTTP port. We check if your WebDAV magic # machinery is enabled and if the client is recognized # as WebDAV client. If yes, we fake the environment # to pretend the ZPublisher to have a WebDAV request. # This sucks like hell but it works pretty fine ;-) if env['REQUEST_METHOD']=='GET' and self._wdav_client_reg: self._munge_webdav_source_port(request, env) # If we're using a resolving logger, try to get the # remote host from the resolver's cache. if hasattr(server.logger, 'resolver'): dns_cache=server.logger.resolver.cache if dns_cache.has_key(env['REMOTE_ADDR']): remote_host=dns_cache[env['REMOTE_ADDR']][2] if remote_host is not None: env['REMOTE_HOST']=remote_host env_has=env.has_key for header in request.header: key,value=header.split(":",1) key=key.lower() value=value.strip() if h2ehas(key) and value: env[h2eget(key)]=value else: key='HTTP_%s' % ("_".join(key.split( "-"))).upper() if value and not env_has(key): env[key]=value env.update(self.env_override) return env
def handle_request(self, request): [path, params, query, fragment] = request.split_uri() while path and path[0] == '/': path = path[1:] if '%' in path: path = unquote(path) env = {} env['REQUEST_URI'] = "/" + path env['REQUEST_METHOD'] = string.upper(request.command) env['SERVER_PORT'] = str(request.channel.server.port) env['SERVER_NAME'] = request.channel.server.server_name env['SERVER_SOFTWARE'] = request['Server'] env['DOCUMENT_ROOT'] = self.document_root parts = string.split(path, "/") # are script_name and path_info ok? env['SCRIPT_NAME'] = "/" + parts[0] if query and query[0] == "?": query = query[1:] env['QUERY_STRING'] = query try: path_info = "/" + string.join(parts[1:], "/") except: path_info = '' env['PATH_INFO'] = path_info env['GATEWAY_INTERFACE'] = 'CGI/1.1' # what should this really be? env['REMOTE_ADDR'] = request.channel.addr[0] env['REMOTE_HOST'] = request.channel.addr[ 0] # TODO: connect to resolver for header in request.header: [key, value] = string.split(header, ": ", 1) key = string.lower(key) if header2env.has_key(key): if header2env[key]: env[header2env[key]] = value else: key = 'HTTP_' + string.upper( string.join(string.split(key, "-"), "_")) env[key] = value ## remove empty environment variables for key in env.keys(): if env[key] == "" or env[key] == None: del env[key] try: httphost = env['HTTP_HOST'] parts = string.split(httphost, ":") env['HTTP_HOST'] = parts[0] except KeyError: pass if request.command in ('put', 'post'): # PUT data requires a correct Content-Length: header # (though I bet with http/1.1 we can expect chunked encoding) request.collector = collector(self, request, env) request.channel.set_terminator(None) else: sin = StringIO.StringIO('') self.continue_request(sin, request, env)