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'])
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)
def test_bad_cache_control(self): resp = DummyResponse(headers=idict({'cache-control':'max-age = fred'})) self.assertEqual(cache.get_max_age(resp,400),60)
def test_simple_case(self): resp = DummyResponse(headers=idict({'cache-control':'max-age = 300'})) self.assertEqual(cache.get_max_age(resp,400),300)
def test_no_useful_headers(self): resp = DummyResponse(headers=idict({})) self.assertEqual(cache.get_last_modified(resp),None)
def test_bad_date(self): resp = DummyResponse(headers=idict({'last-modified':'phil'})) self.assertEqual(cache.get_last_modified(resp),None)
def test_date(self): resp = DummyResponse(headers=idict({'last-modified':formatdate(200.0)})) self.assertEqual(cache.get_last_modified(resp),200.0)
def test_bad_date(self): resp = DummyResponse(headers=idict({'last-modified': 'phil'})) self.assertEqual(cache.get_last_modified(resp), None)
def test_empty_headers(self): resp = DummyResponse(headers=idict({})) self.assertEqual(cache.get_max_age(resp,400),60)
def test_empty_headers(self): resp = DummyResponse(headers=idict({})) self.assertEqual(cache.get_max_age(resp, 400), 60)
def test_bad_max_age(self): resp = DummyResponse(headers=idict({'max-age': 'ten'})) self.assertEqual(cache.get_max_age(resp, 400), 60)
def test_plain_max_age(self): resp = DummyResponse(headers=idict({'max-age': '500'})) self.assertEqual(cache.get_max_age(resp, 400), 500)
def test_bad_cache_control(self): resp = DummyResponse( headers=idict({'cache-control': 'max-age = fred'})) self.assertEqual(cache.get_max_age(resp, 400), 60)
def test_simple_case(self): resp = DummyResponse(headers=idict({'cache-control': 'max-age = 300'})) self.assertEqual(cache.get_max_age(resp, 400), 300)
def test_no_useful_headers(self): resp = DummyResponse(headers=idict({})) self.assertEqual(cache.get_last_modified(resp), None)
def test_plain_max_age(self): resp = DummyResponse(headers=idict({'max-age':'500'})) self.assertEqual(cache.get_max_age(resp,400),500)
def test_bad_max_age(self): resp = DummyResponse(headers=idict({'max-age':'ten'})) self.assertEqual(cache.get_max_age(resp,400),60)
def _initHelpers(self): if not self.isLocal: self._ckjar = idict()
def test_date(self): resp = DummyResponse( headers=idict({'last-modified': formatdate(200.0)})) self.assertEqual(cache.get_last_modified(resp), 200.0)