diff --git a/ftw/http.py b/ftw/http.py index 463b98f..58e3366 100644 --- a/ftw/http.py +++ b/ftw/http.py @@ -437,9 +437,12 @@ def build_request(self): 'data': str(self.request_object.data), 'function': 'http.HttpResponse.build_request' }) - request = request.replace('#data#', util.ensure_str(data_bytes)) + data = util.ensure_str(data_bytes) else: - request = request.replace('#data#', '') + data = '' + + request = request.replace('#data#', data).encode('utf-8', 'strict') + # If we have a Raw Request we should use that instead if self.request_object.raw_request is not None: if self.request_object.encoded_request is not None: @@ -452,11 +455,12 @@ def build_request(self): # We do this regardless of magic if you want to send a literal # '\' 'r' or 'n' use encoded request. request = request.decode('unicode_escape') + if self.request_object.encoded_request is not None: request = base64.b64decode(self.request_object.encoded_request) - request = request.decode('unicode_escape') - # if we have an Encoded request we should use that - self.request = request.encode('utf-8', 'strict') + + # Use the request created + self.request = util.ensure_binary(request) def get_response(self): """ diff --git a/test/integration/test_http.py b/test/integration/test_http.py index d545d92..d2bd8d1 100644 --- a/test/integration/test_http.py +++ b/test/integration/test_http.py @@ -108,8 +108,7 @@ def test_both1(): def test_encoded1(): """Test to make sure a encode request works""" x = ruleset.Input(dest_addr='example.com', - encoded_request='R0VUIC8gSFRUUC8xLjFcclxuSG9zdDogZXhh' - 'bXBsZS5jb21cclxuXHJcbg==') + encoded_request='R0VUIC8gSFRUUC8xLjENCkhvc3Q6IGV4YW1wbGUuY29tDQoNCgo=') http_ua = http.HttpUA() http_ua.send_request(x) assert http_ua.response_object.status == 200 @@ -228,14 +227,6 @@ def test4(): assert http_ua.response_object.status == 200 -def test5(): - """Basic GET without Host on 0.9 - Expect 505 version not supported""" - x = ruleset.Input(dest_addr='example.com', version='HTTP/0.9', headers={}) - http_ua = http.HttpUA() - http_ua.send_request(x) - assert http_ua.response_object.status == 505 - - def test6(): """Basic GET without Host with invalid version (request line) - Expect 505 not supported"""