Exemple #1
0
 def serve_forever(self):
     for record in yaml.load_all(self.stream):
         msg = aadict(record['meta'])
         hdrs = idict(record['headers'])
         if 'client' in msg:
             msg['client'] = msg['client'].split(':')
             msg['client'][1] = int(msg['client'][1])
         if 'server' in msg:
             msg['server'] = msg['server'].split(':')
             msg['server'][1] = int(msg['server'][1])
         self.logger.logMessage(msg, record['rline'], hdrs,
                                record['content'])
Exemple #2
0
    def sendRequest(self, content, method='GET'):
        req = urllib2.Request(
            '%s://%s:%d%s' %
            (self.options.ssl and 'https' or 'http', self.options.remote[0],
             self.options.remote[1], self.path), None, self.headers)

        # not using the build_opener as i want to handle 302s...
        #   opener  = urllib2.build_opener()
        opener = urllib2.OpenerDirector()
        opener.add_handler(urllib2.HTTPSHandler())
        opener.add_handler(urllib2.HTTPHandler())

        req.add_header(
            'Host', '%s:%d' % (self.options.remote[0], self.options.remote[1]))

        if method not in 'GET':
            req.get_method = lambda: method

        if content is not None:
            resp = opener.open(req, content)
        else:
            resp = opener.open(req)

        info = resp.info()
        data = resp.read()

        def sedform(data):
            for xform in self.options.responseSed:
                data = xform(data)
            return data

        data = sedform(data)
        headers = idict({k: sedform(v) for k, v in info.items()})

        self.logResponse(resp, headers, data)
        self.sendResponse(resp, headers, data)
Exemple #3
0
 def test_bad_cache_control(self):
     resp = DummyResponse(headers=idict({'cache-control':'max-age = fred'}))
     self.assertEqual(cache.get_max_age(resp,400),60)
Exemple #4
0
 def test_simple_case(self):
     resp = DummyResponse(headers=idict({'cache-control':'max-age = 300'}))
     self.assertEqual(cache.get_max_age(resp,400),300)
Exemple #5
0
 def test_no_useful_headers(self):    
     resp = DummyResponse(headers=idict({}))
     self.assertEqual(cache.get_last_modified(resp),None)
Exemple #6
0
 def test_bad_date(self):
     resp = DummyResponse(headers=idict({'last-modified':'phil'}))
     self.assertEqual(cache.get_last_modified(resp),None)
Exemple #7
0
 def test_date(self):
     resp = DummyResponse(headers=idict({'last-modified':formatdate(200.0)}))
     self.assertEqual(cache.get_last_modified(resp),200.0)
Exemple #8
0
 def test_bad_date(self):
     resp = DummyResponse(headers=idict({'last-modified': 'phil'}))
     self.assertEqual(cache.get_last_modified(resp), None)
Exemple #9
0
 def test_empty_headers(self):
     resp = DummyResponse(headers=idict({}))
     self.assertEqual(cache.get_max_age(resp,400),60)
Exemple #10
0
 def test_empty_headers(self):
     resp = DummyResponse(headers=idict({}))
     self.assertEqual(cache.get_max_age(resp, 400), 60)
Exemple #11
0
 def test_bad_max_age(self):
     resp = DummyResponse(headers=idict({'max-age': 'ten'}))
     self.assertEqual(cache.get_max_age(resp, 400), 60)
Exemple #12
0
 def test_plain_max_age(self):
     resp = DummyResponse(headers=idict({'max-age': '500'}))
     self.assertEqual(cache.get_max_age(resp, 400), 500)
Exemple #13
0
 def test_bad_cache_control(self):
     resp = DummyResponse(
         headers=idict({'cache-control': 'max-age = fred'}))
     self.assertEqual(cache.get_max_age(resp, 400), 60)
Exemple #14
0
 def test_simple_case(self):
     resp = DummyResponse(headers=idict({'cache-control': 'max-age = 300'}))
     self.assertEqual(cache.get_max_age(resp, 400), 300)
Exemple #15
0
 def test_no_useful_headers(self):
     resp = DummyResponse(headers=idict({}))
     self.assertEqual(cache.get_last_modified(resp), None)
Exemple #16
0
 def test_plain_max_age(self):
     resp = DummyResponse(headers=idict({'max-age':'500'}))
     self.assertEqual(cache.get_max_age(resp,400),500)
Exemple #17
0
 def test_bad_max_age(self):
     resp = DummyResponse(headers=idict({'max-age':'ten'}))
     self.assertEqual(cache.get_max_age(resp,400),60)
Exemple #18
0
 def _initHelpers(self):
   if not self.isLocal:
     self._ckjar = idict()
Exemple #19
0
 def _initHelpers(self):
     if not self.isLocal:
         self._ckjar = idict()
Exemple #20
0
 def test_date(self):
     resp = DummyResponse(
         headers=idict({'last-modified': formatdate(200.0)}))
     self.assertEqual(cache.get_last_modified(resp), 200.0)