Пример #1
0
import logging, socket
from http.client import HTTPSConnection, HTTPException, _CS_IDLE
from threading import RLock

from handlers.dummy import Dummy
from server.response import wrap as wrap_response


from server import logger
http_debug = logger('http_debug').debug
del logger

_IDLE = 4 * 60 + 57 # seconds

class Upstream (Dummy):
	"""
	simple pass-through handler
	"""
	def _call_upstream(self, conn, request, first_attempt = True):
		try:
			http_debug("calling upstream (%s) %s", conn.host, request)
			conn.request(request.command, request.path, request.body, dict(request.headers))
			return conn.getresponse()
		except (socket.error, HTTPException) as ex:
			logging.warn("[%s:%s] (%s) %s %s", type(ex), ex, conn.host, request.command, request.path)
			conn.close()
			if first_attempt:
				return self._call_upstream(conn, request, False)
			raise Exception(conn.host, request.command, request.path, ex)
		finally:
			conn.last_call = request.started_at
Пример #2
0
import logging, time
from http.server import BaseHTTPRequestHandler

from handlers import ExceptionResponse
from content import decompress, str_
import devices
import config, features

from server import logger
access_log = logger('access', False, 'INFO')
http_debug = logger('http_debug', 'DEBUG').debug
del logger

import server.request as request


class Handler(BaseHTTPRequestHandler):
    """
	Main request handler
	"""
    # this needs to be as light as possible, because one instance gets created for each client connection (and is the actual HTTP request object)
    # of course, this is the part that grew quite a lot during development...
    protocol_version = 'HTTP/1.1'
    error_message_format = ''
    error_content_type = 'text/plain'
    # wbufsize = 16 * 1024 # 16k

    _prefix_len = len(config.server_path_prefix
                      or b'x') - 1  # without the final /

    def handle_call(self, device):
Пример #3
0
import logging, time
from http.server import BaseHTTPRequestHandler

from handlers import ExceptionResponse
from content import decompress, str_
import devices
import config, features

from server import logger
access_log = logger('access', False, 'INFO')
http_debug = logger('http_debug', 'DEBUG').debug
del logger

import server.request as request


class Handler (BaseHTTPRequestHandler):
	"""
	Main request handler
	"""
	# this needs to be as light as possible, because one instance gets created for each request (actually, this _is_ the request)
	# of course, this is the part that grew quite a lot during development...
	protocol_version = 'HTTP/1.1'
	error_message_format = ''
	error_content_type = 'text/plain'
	# wbufsize = 16 * 1024 # 16k

	_prefix_len = len(config.server_path_prefix or b'x') - 1 # without the final /

	def handle_call(self):
		# logging.debug("## %s", self.requestline)
Пример #4
0
import logging, socket
from http.client import HTTPSConnection, HTTPException, _CS_IDLE
from threading import RLock

from handlers.dummy import Dummy
from server.response import wrap as wrap_response

from server import logger
http_debug = logger('http_debug').debug
del logger

_IDLE = 4 * 60 + 57  # seconds


class Upstream(Dummy):
    """
	simple pass-through handler
	"""
    def _call_upstream(self, conn, request, first_attempt=True):
        try:
            http_debug("calling upstream (%s) %s", conn.host, request)
            conn.request(request.command, request.path, request.body,
                         dict(request.headers))
            return conn.getresponse()
        except (socket.error, HTTPException) as ex:
            logging.warn("[%s:%s] (%s) %s %s", type(ex), ex, conn.host,
                         request.command, request.path)
            conn.close()
            if first_attempt:
                return self._call_upstream(conn, request, False)
            raise Exception(conn.host, request.command, request.path, ex)