Пример #1
0
    def get(self):
        """

        :return: http response data, status, status message

        """
        global_config_data = get_cli_data()
        static_root = global_config_data.get("static", ".")
        request_expire_days = self.get_header("expires")
        now_time = self.get_now_time()
        if request_expire_days and now_time <= request_expire_days:
            return "", HttpStatus.RESOURCE_NOT_MODIFIED, HttpStatusMsg.RESOURCE_NOT_MODIFIED
        request_etag = self.get_header("if-none-match")
        file_path = self.get_request_url()
        file_absolute_path = static_root + file_path
        if not os.path.exists(file_absolute_path):
            return "404", HttpStatus.NOT_FOUND, HttpStatusMsg.NOT_FOUND
        file_etag, file_data = self.get_file_etag(file_absolute_path)
        if request_etag and request_etag == file_etag:
            return "", HttpStatus.RESOURCE_NOT_MODIFIED, HttpStatusMsg.RESOURCE_NOT_MODIFIED
        expires = self.generate_expire_date(expires_days=7)
        file_extension = file_path.split(".")[-1]
        self.set_header({
            "ETag": file_etag,
            "Expires": expires,
            "Content-Type": content_type.get(file_extension)
        })
        return file_data, HttpStatus.SUCCESS, HttpStatusMsg.SUCCESS
Пример #2
0
 def __init__(self, handlers, settings=None, **kwargs):
     cli_data = get_cli_data()
     self.port = int(kwargs.get("port", 0)) or int(cli_data.get("port", DEFAULT_PORT))
     self.settings = settings
     self.handlers = handlers
     set_cli_data(self.settings)
     self.logger = init_logger()
     self.EOL1 = b'\n\n'
     self.EOL2 = b'\n\r\n'
     self.response = ""
Пример #3
0
 def __init__(self, handlers, settings=None, **kwargs):
     cli_data = get_cli_data()
     self.port = int(kwargs.get("port", 0)) or int(
         cli_data.get("port", DEFAULT_PORT))
     self.settings = settings
     self.handlers = handlers
     set_cli_data(self.settings)
     self.logger = init_logger()
     self.EOL1 = b'\n\n'
     self.EOL2 = b'\n\r\n'
     self.response = ""
Пример #4
0
def init_logger(config_path=None):
    """get the logger object

    :param config_path: log config file
    :return: logger

    """
    cli_data = get_cli_data()
    log_enable = cli_data.get("log_enable")
    if not log_enable:
        return logging
    if isinstance(log_enable, str) and log_enable.lower() != "true":
        return logging
    path = os.path.dirname(__file__) + "/log.conf"
    config_file = config_path or path
    logging.config.fileConfig(config_file)
    logger = logging.getLogger()
    return logger
Пример #5
0
    def __init__(self, handlers, settings=None, **kwargs):
        """

        :param handlers: handlers mapping, dict type
        :param settings: settings mapping, dict type
        :param kwargs: options

        """
        self.settings = settings
        self.handlers = handlers
        set_cli_data(self.settings)
        set_cli_data(kwargs)
        cli_data = get_cli_data()
        self.port = int(cli_data.get("port", DEFAULT_PORT))
        self.logger = init_logger()
        self.EOL1 = b'\n\n'
        self.EOL2 = b'\n\r\n'
        self.response = ""
Пример #6
0
    def __init__(self, handlers, settings=None, **kwargs):
        """

        :param handlers: handlers mapping, dict type
        :param settings: settings mapping, dict type
        :param kwargs: options

        """
        self.handlers = handlers
        set_cli_data(settings)
        set_cli_data(kwargs)
        cli_data = get_cli_data()
        self.settings = cli_data
        self.port = int(cli_data.get("port", DEFAULT_PORT))
        log_conf = self.settings.get("log_conf", None) if self.settings else kwargs.get("log_conf", None)
        self.logger = init_logger(config_path=log_conf)
        self.EOL1 = '\n\n'
        self.EOL2 = '\n\r\n'
        self.response = ""
Пример #7
0
    def __init__(self, handlers, settings=None, **kwargs):
        """

        :param handlers: handlers mapping, dict type
        :param settings: settings mapping, dict type
        :param kwargs: options

        """
        self.settings = settings
        self.handlers = handlers
        set_cli_data(self.settings)
        set_cli_data(kwargs)
        cli_data = get_cli_data()
        self.port = int(cli_data.get("port", DEFAULT_PORT))
        log_conf = self.settings.get("log_conf",
                                     None) if self.settings else kwargs.get(
                                         "log_conf", None)
        self.logger = init_logger(config_path=log_conf)
        self.EOL1 = b'\n\n'
        self.EOL2 = b'\n\r\n'
        self.response = ""
Пример #8
0
 def get(self):
     global_config_data = get_cli_data()
     static_root = global_config_data.get("static", ".")
     request_expire_days = self.get_header("expires")
     now_time = self.get_now_time()
     if request_expire_days and now_time <= request_expire_days:
         return "", HttpStatus.RESOURCE_NOT_MODIFIED, HttpStatusMsg.RESOURCE_NOT_MODIFIED
     request_etag = self.get_header("if-none-match")
     file_path = self.get_request_url()
     file_absolute_path = static_root+file_path
     if not os.path.exists(file_absolute_path):
         return "404", HttpStatus.NOT_FOUND, HttpStatusMsg.NOT_FOUND
     file_etag, file_data = self.get_file_etag(file_absolute_path)
     if request_etag and request_etag == file_etag:
         return "", HttpStatus.RESOURCE_NOT_MODIFIED, HttpStatusMsg.RESOURCE_NOT_MODIFIED
     expires = self.generate_expire_date(expires_days=7)
     file_extension = file_path.split(".")[-1]
     self.set_header({
         "ETag": file_etag,
         "Expires": expires,
         "Content-Type": content_type.get(file_extension)
     })
     return file_data
Пример #9
0
 def __init__(self, handles, url):
     self.__handlers = handles
     self.__url = url
     self.__is_static_enable = get_cli_data().get("static")
     self.__is_debug = get_cli_data().get("debug")
Пример #10
0
 def __init__(self, handles, url):
     self.__handlers = handles
     self.__url = url
     self.__is_static_enable = get_cli_data().get("static")
     self.__is_debug = get_cli_data().get("debug")