Пример #1
0
 def __init__(self, red):
     self.red = red
     if "gzip" in red.parsed_hdrs.get('content-encoding', []):
         req_hdrs = [h for h in red.orig_req_hdrs if
                     h[0].lower() != 'accept-encoding']
         RedFetcher.__init__(self, red.uri, red.method, req_hdrs, red.req_body,
                             red.status_cb, [], "conneg")
     else:
         self.red.gzip_support = False
Пример #2
0
 def __init__(self, red):
     self.red = red
     if red.parsed_hdrs.has_key('last-modified'):
         date_str = time.strftime('%a, %d %b %Y %H:%M:%S GMT',
                                  time.gmtime(red.parsed_hdrs['last-modified']))
         req_hdrs = red.req_hdrs + [
             ('If-Modified-Since', date_str),
         ]
         RedFetcher.__init__(self, red.uri, red.method, req_hdrs, red.req_body,
                             red.status_cb, [], "LM validation")
     else:
         self.red.ims_support = False
Пример #3
0
    def __init__(self, uri, method="GET", req_hdrs=None, req_body=None,
                 status_cb=None, body_procs=None):
        self.orig_req_hdrs = req_hdrs or []
        if 'user-agent' not in [i[0].lower() for i in self.orig_req_hdrs]:
            self.orig_req_hdrs.append(
                ("User-Agent", "RED/%s (http://redbot.org/about)" % __version__))
        rh = self.orig_req_hdrs + [('Accept-Encoding', 'gzip')]
        RedFetcher.__init__(self, uri, method, rh, req_body,
                            status_cb, body_procs, req_type=method)

        # check the URI
        if not re.match("^\s*%s\s*$" % absolute_URI, uri, re.VERBOSE):
            self.setMessage('uri', rs.URI_BAD_SYNTAX)
        if len(uri) > max_uri:
            self.setMessage('uri', rs.URI_TOO_LONG, uri_len=len(uri))
Пример #4
0
 def __init__(self, red):
     self.red = red
     if red.parsed_hdrs.has_key('etag'):
         weak, etag = red.parsed_hdrs['etag']
         if weak:
             weak_str = "W/"
             # TODO: message on weak etag
         else:
             weak_str = ""
         etag_str = '%s"%s"' % (weak_str, etag)
         req_hdrs = red.req_hdrs + [
             ('If-None-Match', etag_str),
         ]
         RedFetcher.__init__(self, red.uri, red.method, req_hdrs, red.req_body,
                             red.status_cb, [], "ETag validation")
     else:
         self.red.inm_support = False
Пример #5
0
 def __init__(self, red):
     self.red = red
     if 'bytes' in red.parsed_hdrs.get('accept-ranges', []):
         if len(red.res_body_sample) == 0: return
         sample_num = random.randint(0, len(red.res_body_sample) - 1)
         sample_len = min(96, len(red.res_body_sample[sample_num][1]))
         self.range_start = red.res_body_sample[sample_num][0]
         self.range_end = self.range_start + sample_len
         self.range_target = red.res_body_sample[sample_num][1][:sample_len + 1]
         if self.range_start == self.range_end: return # wow, that's a small body.
         # TODO: currently uses the compressed version (if available. Revisit.
         req_hdrs = red.req_hdrs + [
                 ('Range', "bytes=%s-%s" % (self.range_start, self.range_end))
         ]
         RedFetcher.__init__(self, red.uri, red.method, req_hdrs, red.req_body,
                             red.status_cb, [], "range")
     else:
         self.red.partial_support = False