Example #1
0
 def set_cache_control(self, request, path, mtime, etag):
     max_age = self.max_ages and self.get_max_age(path) or 0
     if request.version == "1.0":
         request.response['Last-Modified'] = http_date.build_http_date(
             mtime)
         if max_age:
             request.response['Expires'] = http_date.build_http_date(
                 mtime + max_age)
     else:
         request.response['Etag'] = '"' + etag + '"'
         if max_age:
             request.response['Cache-Control'] = "max-age=%d" % max_age
Example #2
0
 def __init__(self, request):
     self.request = request
     self.reply_headers = [('Server', skitai.NAME),
                           ('Date', http_date.build_http_date(time.time()))]
     self.outgoing = producers.fifo()
     self._is_done = False
     self.stime = time.time()
     self.htime = 0
     self.content_type = None
     self.current_app = None
     self.current_env = None
Example #3
0
 def __init__(self, request):
     self.request = request
     self.reply_headers = [('Server', skitai.NAME),
                           ('Date', http_date.build_http_date(time.time()))]
     altsvc = self.request.channel.server.altsvc
     if altsvc:
         self.reply_headers.append(("Alt-Svc", altsvc.ALTSVC_HEADER))
     self.outgoing = producers.fifo()
     self._is_done = False
     self.stime = time.time()
     self.htime = 0
     self.content_type = None
     self.current_app = None
     self.current_env = None
Example #4
0
    def build_error_template(self, why='', was=None):
        global DEFAULT_ERROR_MESSAGE

        exc_info = None
        if type(why) is tuple:  # sys.exc_info ()
            if self.current_app and not self.current_app.debug:
                why = None
            exc_info, why = why, ''

        error = {}
        if self.request.get_header('accept',
                                   '').find("application/json") != -1:
            message = why or self.reply_message.lower()
            debug = None
            if exc_info:
                debug = 'see traceback'
            return self.fault(message, 0, debug, exc_info=exc_info)

        else:
            self.update('content-type', 'text/html')
            error['detail'] = why
            error['time'] = http_date.build_http_date(time.time())
            error['url'] = urljoin(
                "%s://%s/" %
                (self.request.get_scheme(), self.request.get_header("host")),
                self.request.uri)
            error['software'] = skitai.NAME
            error['mode'] = exc_info and 'debug' or 'normal'
            error['code'] = self.reply_code
            error['message'] = self.reply_message
            error["traceback"] = exc_info and catch(1, exc_info) or None

            content = None
            if self.current_app and hasattr(self.current_app, 'render_error'):
                try:
                    content = self.current_app.render_error(error, was)
                except:
                    self.request.logger.trace()
                    if self.current_app.debug:
                        error[
                            "traceback"] += "<h2 style='padding-top: 40px;'>Exception Occured During Building Error Template</h2>" + catch(
                                1)

            return content or (DEFAULT_ERROR_MESSAGE % error)
Example #5
0
    def build_error_template(self, why='', errno=0, was=None):
        global DEFAULT_ERROR_MESSAGE

        exc_info = None
        if type(why) is tuple:  # sys.exc_info ()
            if self.current_app and not self.current_app.debug:
                why = None
            exc_info, why = why, ''

        is_html_response = self.request.get_header('accept',
                                                   '').find("text/html") != -1
        error = {
            'code':
            self.reply_code,
            'errno':
            errno,
            'message':
            self.reply_message,
            'detail':
            why,
            'mode':
            exc_info and 'debug' or 'normal',
            'time':
            http_date.build_http_date(time.time()),
            'url':
            urljoin(
                "%s://%s/" %
                (self.request.get_scheme(), self.request.get_header("host")),
                self.request.uri),
            'software':
            skitai.NAME,
            'debug':
            None,
            "traceback":
            exc_info and catch(is_html_response and 1 or 2, exc_info) or None,
        }
        if self.current_app and hasattr(self.current_app, 'render_error'):
            content = None
            try:
                content = self.current_app.render_error(error, was)
            except:
                self.request.logger.trace()
                if self.current_app.debug:
                    if is_html_response:
                        error[
                            "traceback"] += "<h2 style='padding-top: 40px;'>Exception Occured During Building Error Template</h2>" + catch(
                                1)
                    else:
                        error["traceback"] += [
                            "Exception Occured During Building Error Template"
                        ] + catch(2)
            if content:
                return content

        if is_html_response:
            self.update('content-type', 'text/html')
            return DEFAULT_ERROR_MESSAGE % {
                k: v or ''
                for k, v in error.items()
            }
        else:
            return self.fault(error["message"].lower(),
                              errno,
                              None,
                              error["detail"],
                              exc_info=error["traceback"])
Example #6
0
 def set_cache(self, max_age=0):
     if self.request.version == "1.0":
         self.set_header('Expires',
                         http_date.build_http_date(time.time() + max_age))
     else:
         self.set_header('Cache-Control', "max-age=%d" % max_age)