def setup(self): if self.server.cert_file: self.connection = self.request self.rfile = socket._fileobject(self.request, "rb", self.rbufsize) self.wfile = socket._fileobject(self.request, "wb", self.wbufsize) else: WSGIRequestHandler.setup(self)
def __init__(self, *args, **kwargs): global tracer global q self._response_headers = [] # print DEBUG_ENABLED # self.http_version = "1.1" DBG("START") # STDERR("START: debug_enable=%s"%DEBUG_ENABLED) if DEBUG_ENABLED: # STDERR("bps: %s" % tracer.get_all_breaks()) if tracer.get_all_breaks(): q.put("set_continue") tracer.set_trace() tracer.process_pending_commands() # STDERR("bps: %s" % tracer.get_all_breaks()) # STDERR("%d" % q.unfinished_tasks) else: # Debug is not enable and there are no breakpoints # continue without debugger overhead # STDERR(repr(tracer.get_all_breaks())) sys.settrace(None) WSGIRequestHandler.__init__(self, *args, **kwargs) # STDOUT("aqui") # print self.requestline # print self.headers try: WSOUT("REQUEST_HEADERS", "%s\n%s\n%s" % ("-" * 20, self.requestline, self.headers)) except AttributeError: pass DBG("STOP")
def finish(self): # Prevent the socket from being closed, except for status 401 (auth needed) # TODO: if no Content-Length is specified, should close. if not self.handler.last_status.startswith('200') and self.command == 'POST': # Request was a POST but it did not succeed, so we must purge the # request body so it doesn't run into the next request. self.request.read(-1) if self.headers.get('Connection', '').lower() != 'keep-alive' or self.handler.last_status.startswith('401'): WSGIRequestHandler.finish(self)
def handle(self): fd_sets = select.select([self.rfile], [], [], 1.0) if not fd_sets[0]: # Sometimes WebKit times out waiting for us. return if PY3: super(GhostWSGIRequestHandler, self).handle() else: WSGIRequestHandler.handle(self)
def do(self): self.log_message(self.requestline.rpartition(' ')[0] .replace('%', '%%')) if self.server.redirect_static: if any(map(self.path.startswith, ['/static/', '/media/'])): return self.write('HTTP/1.1 302 Found\nLocation: http://%s%s\n' % (self.server.uwsgi_host, self.path)) setattr(self.server, 'base_environ', {}) env = WSGIRequestHandler.get_environ(self) qs = env['QUERY_STRING'] env = dict(dict({ 'REQUEST_URI': env['PATH_INFO'] + (('?' + qs) if qs else ''), 'CONTENT_LENGTH': '', 'DOCUMENT_ROOT': '', 'REMOTE_PORT': str(self.client_address[1]), }, **env), **{ 'SERVER_ADDR': self.server.uwsgi_addr, 'SERVER_NAME': self.server.uwsgi_host, 'SERVER_PORT': str(self.server.uwsgi_port), 'CONTENT_TYPE': get_content_type(self.headers) or '', 'HTTP_HOST': self.server.uwsgi_host, }) env.pop('REMOTE_HOST', 0) env.pop('HTTP_REFERER', 0) cl = env['CONTENT_LENGTH'] body = repr(self.rfile.read(int(cl))) if cl else '' resp = ask_uwsgi((self.server.uwsgi_addr, self.server.uwsgi_port), var=env, body=body) self.write(resp) h, _, b = resp.partition('\r\n\r\n') print('%s\n%s' % (h, len(b)))
def get_environ(self): env = _WSGIRequestHandler.get_environ(self) param = env.get('HTTP_CONNECTION', None) if param == 'close': self.close_connection = 1 elif param == 'keep-alive': self.close_connection = 0 return env
def get_environ(self): """ wsgiref simple server adds content-type text/plain to everything, this removes it if it's not actually in the headers. """ # Note: Can't use super since this is an oldstyle class in python 2.x environ = WSGIRequestHandler.get_environ(self).copy() if self.headers.get('content-type') is None: del environ['CONTENT_TYPE'] return environ
def get_environ(self): wsgi_environment = WSGIRequestHandler.get_environ(self) wsgi_environment.update({ "de.inm7.sfb1451.entry.dataset_root": "/tmp/sfb-test", "de.inm7.sfb1451.entry.home": "/tmp/sfb-test-home", "de.inm7.sfb1451.entry.templates": str(template_dir) }) return wsgi_environment
def get_environ(self): env = WSGIRequestHandler.get_environ(self) if isinstance(self.request, ssl.SSLSocket): env['HTTPS'] = 'on' # JB: Add handling of wsgi.url_scheme env['wsgi.url_scheme'] = 'https' # JB: Add handling of script name if env['SCRIPT_NAME'] == "" and env['PATH_INFO'].startswith(root): env['SCRIPT_NAME'] = root env['PATH_INFO'] = env['PATH_INFO'][len(root):] return env
def log_request(*args, **kw): return WSGIRequestHandler.log_request(*args, **kw)
def do_GET(self): if self.path == "/wsdl": self.path = "/" WSGIRequestHandler.do_GET(self)
def close(self): WSGIRequestHandler.finish(self) asyncore.dispatcher.close(self)
def log_request(*args, **kw): if not self.quiet: return WSGIRequestHandler.log_request(*args, **kw)
def address_string(self): if self.server.byfd or self.server.socket_type == socket.AF_UNIX: return '0.0.0.0' return WSGIRequestHandler.address_string(self)
def __init__(self, sock, client_addr, server): if server.socket_type == socket.AF_UNIX: client_addr = ['0.0.0.0'] WSGIRequestHandler.__init__(self, sock, client_addr, server)
def __init__(self, *args, **kwargs): self.logger = logging.getLogger('thebot.batteries.http') WSGIRequestHandler.__init__(self, *args, **kwargs)
def get_environ(self): env = WSGIRequestHandler.get_environ(self) env['resource_controller'] = controller_obj return env
def log_request(self, code="-", size="-"): WSGIRequestHandler.log_request(self, code, size)
def log_request(self, *args, **kw): if not self.parent.quiet: return WSGIRequestHandler.log_request(self, *args, **kw)
def get_environ(self): env = WSGIRequestHandler.get_environ(self) if isinstance(self.request, ssl.SSLSocket): env['HTTPS'] = 'on' return env
def handle(self): WSGIRequestHandler.handle(self) if 'shutdown=1' in self.raw_requestline: import threading threading.Thread(target=self.shutdown_server()).start()
def __init__(self, request, client_address, server): # Everything expects a (host, port) pair, so let's provide something like that. client_address = (client_address, 0) WSGIRequestHandler.__init__(self, request, client_address, server)
def log_request(self, *args): if 'GOCEPT_SELENIUM_VERBOSE_LOGGING' in os.environ: WSGIRequestHandler.log_request(self, *args)
def log_request(*args, **kwargs): if not self.quiet: return WSGIRequestHandler.log_request( *args, **kwargs)
def log_message(self, format, *args): if self.verbose_logging: WSGIRequestHandler.log_message(self, format, *args)
def log_request(*argv, **kwarg): return WSGIRequestHandler.log_request(*argv, **kwarg)
def __init__(self, request, client_address, server): server.get_app = lambda: app server.base_environ = self.setup_environ() WSGIRequestHandler.__init__(self, request, client_address, server)
def do_POST(self): WSGIRequestHandler.do_POST(self)
def handle(self): try: WSGIRequestHandler.handle(self) except socket.error: # Avoid garbage on the kodi log pass
def get_environ(self): ''' Just in case I need to add something... ''' return WSGIRequestHandler.get_environ(self)