diff --git a/dotextensions/server/handlers/basic_handlers.py b/dotextensions/server/handlers/basic_handlers.py index 6e73a3c..b9b7e2c 100644 --- a/dotextensions/server/handlers/basic_handlers.py +++ b/dotextensions/server/handlers/basic_handlers.py @@ -104,6 +104,8 @@ def get_request_result(self, command, comp: RequestCompiler): data = {} data.update(response_data['response']) # deprecated data.update(response_data) + if 'cookie' in resp.request.headers: + comp.httpdef.headers['cookie'] = resp.request.headers['cookie'] try: data.update({"http": self.get_http_from_req(comp.httpdef)}) except Exception as e: diff --git a/dothttp/__version__.py b/dothttp/__version__.py index 1358f97..f252537 100644 --- a/dothttp/__version__.py +++ b/dothttp/__version__.py @@ -1 +1 @@ -__version__ = '0.0.40a5' +__version__ = '0.0.40a6' diff --git a/test/core/requests/cookie.http b/test/core/requests/cookie.http new file mode 100644 index 0000000..a3dcc9c --- /dev/null +++ b/test/core/requests/cookie.http @@ -0,0 +1,8 @@ +@name('set-cookie') +GET https://httpbin.org/cookies/set/dev/ram + + + + +@name('confirm-cookie-sent') +GET https://httpbin.org/cookies \ No newline at end of file diff --git a/test/core/test_request.py b/test/core/test_request.py index b050251..0408a58 100644 --- a/test/core/test_request.py +++ b/test/core/test_request.py @@ -4,7 +4,7 @@ import unittest from dothttp.exceptions import * -from dothttp.request_base import CurlCompiler, HttpFileFormatter +from dothttp.request_base import DOTHTTP_COOKIEJAR, CurlCompiler, HttpFileFormatter, RequestBase from test import TestBase dir_path = os.path.dirname(os.path.realpath(__file__)) @@ -248,6 +248,33 @@ def test_trailing_commas_are_ok(self): self.assertEqual('https://dev.dothttp.dev/', fourth_one.url) self.assertEqual('POST', fourth_one.method) + def test_cookie(self): + # This is an integration test + filename = f"{base_dir}/cookie.http" + req_comp = self.get_req_comp(filename, target="set-cookie") + resp = req_comp.get_response() + # confirm cookie is recognized by httpbin.org + self.assertEqual({ + "cookies": { + "dev": "ram" + } + }, resp.json()) + + req_comp2 = self.get_req_comp(filename, target="confirm-cookie-sent") + self.assertEqual("dev=ram", req_comp2.get_request().headers.get('cookie')) + resp = req_comp2.get_response() + + self.assertEqual({ + "cookies": { + "dev": "ram" + } + }, resp.json()) + os.remove(DOTHTTP_COOKIEJAR) + RequestBase.global_session.cookies.clear() + + + + if __name__ == "__main__": unittest.main() diff --git a/test/extensions/commands/cookie.http b/test/extensions/commands/cookie.http new file mode 100644 index 0000000..158a197 --- /dev/null +++ b/test/extensions/commands/cookie.http @@ -0,0 +1,3 @@ +@name('set-cookie') +GET https://httpbin.org/cookies/set/dev/ram + diff --git a/test/extensions/test_commands.py b/test/extensions/test_commands.py index fddd043..45d8a84 100644 --- a/test/extensions/test_commands.py +++ b/test/extensions/test_commands.py @@ -6,6 +6,7 @@ from dotextensions.server.handlers.basic_handlers import RunHttpFileHandler, GetNameReferencesHandler, \ ContentNameReferencesHandler from dotextensions.server.models import Command +from dothttp.request_base import DOTHTTP_COOKIEJAR, RequestBase from test import TestBase from test.core.test_certs import http_base, cert_base @@ -214,6 +215,20 @@ def test_env(self): result = self.execute_file(f"{command_dir}/isolated/env.http", env=["simple"]) self.assertEqual(200, result.result['status']) + + def test_execute(self): + result = self.execute_file(f"{command_dir}/cookie.http", target="set-cookie") + self.assertEqual("""@name("set-cookie") +GET "https://httpbin.org/cookies/set/dev/ram" +"cookie": "dev=ram" + + + +""", result.result['http']) + os.remove(DOTHTTP_COOKIEJAR) + RequestBase.global_session.cookies.clear() + + def test_property(self): result = self.execute_file(f"{command_dir}/isolated/env.http", properties={"path": "get"}) self.assertEqual(200, result.result['status'])