Skip to content

Commit ff6094e

Browse files
committed
Fix request URL and HTTP method definitions
Closes: #94
1 parent 217bfe5 commit ff6094e

5 files changed

Lines changed: 48 additions & 7 deletions

File tree

fdk/context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,10 @@ def GetResponseHeaders(self):
106106
return self.__response_headers
107107

108108
def RequestURL(self):
109-
return self.__invoke_context._request_url
109+
return self._request_url
110110

111111
def Method(self):
112-
return self.__invoke_context._method
112+
return self._method
113113

114114
def __is_gateway(self):
115115
return (constants.FN_INTENT in self.__headers and

fdk/fixtures.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,16 @@ def setup_headers(deadline=None, headers=None,
5353
new_headers = hs.encap_headers(headers)
5454
new_headers.update({
5555
constants.FN_INTENT: constants.INTENT_HTTP_REQUEST,
56-
constants.FN_HTTP_REQUEST_URL: request_url,
57-
constants.FN_HTTP_METHOD: method,
5856
})
5957
elif headers is not None:
6058
for k, v in headers.items():
6159
new_headers.update({k: v})
6260

61+
new_headers.update({
62+
constants.FN_HTTP_REQUEST_URL: request_url,
63+
constants.FN_HTTP_METHOD: method,
64+
})
65+
6366
if deadline is None:
6467
now = dt.datetime.now(dt.timezone.utc).astimezone()
6568
now += dt.timedelta(0, float(constants.DEFAULT_DEADLINE))

fdk/tests/funcs.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,8 @@ def verify_request_headers(ctx, **kwargs):
114114

115115

116116
def access_request_url(ctx, **kwargs):
117-
hs = ctx.Headers()
118117
method = ctx.Method()
119-
request_url = hs.get("Fn-Http-Request-Url")
118+
request_url = ctx.RequestURL()
120119
return response.Response(
121120
ctx, response_data="OK", headers={
122121
"Response-Request-URL": request_url,

fdk/tests/test_http_stream.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,42 @@ def test_log_frame_header(monkeypatch, capsys):
193193
captured = capsys.readouterr()
194194
assert "\nfoo=12345\n" in captured.out
195195
assert "\nfoo=12345\n" in captured.err
196+
197+
198+
@pytest.mark.asyncio
199+
async def test_request_url_and_method_no_gateway():
200+
url_path = "/call"
201+
method = "POST"
202+
call = await fixtures.setup_fn_call(
203+
funcs.access_request_url,
204+
request_url=url_path,
205+
method=method,
206+
)
207+
content, status, headers = await call
208+
209+
assert "response-request-url" in headers
210+
assert "request-method" in headers
211+
212+
assert url_path == headers.get("response-request-url")
213+
assert method == headers.get("request-method")
214+
215+
216+
@pytest.mark.asyncio
217+
async def test_request_url_and_method_with_gateway():
218+
url_path = "/t/app/path"
219+
method = "GET"
220+
call = await fixtures.setup_fn_call(
221+
funcs.access_request_url,
222+
request_url=url_path,
223+
method=method,
224+
gateway=True
225+
)
226+
content, status, headers = await call
227+
228+
assert "response-request-url" not in headers
229+
assert "request-method" not in headers
230+
assert "fn-http-h-response-request-url" in headers
231+
assert "fn-http-h-request-method" in headers
232+
233+
assert url_path == headers.get("fn-http-h-response-request-url")
234+
assert method == headers.get("fn-http-h-request-method")

fdk/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = "0.1.7"
1+
VERSION = "0.1.8"

0 commit comments

Comments
 (0)