def __init__(self, app_id, app_name, fn_id, fn_name, call_id, content_type="application/octet-stream", deadline=None, config=None, headers=None, request_url=None, method="POST", fn_format=None, tracing_context=None): """ Request context here to be a placeholder for request-specific attributes :param app_id: Fn App ID :type app_id: str :param app_name: Fn App name :type app_name: str :param fn_id: Fn App Fn ID :type fn_id: str :param fn_name: Fn name :type fn_name: str :param call_id: Fn call ID :type call_id: str :param content_type: request content type :type content_type: str :param deadline: request deadline :type deadline: str :param config: an app/fn config :type config: dict :param headers: request headers :type headers: dict :param request_url: request URL :type request_url: str :param method: request method :type method: str :param fn_format: function format :type fn_format: str :param tracing_context: tracing context :type tracing_context: TracingContext """ self.__app_id = app_id self.__fn_id = fn_id self.__call_id = call_id self.__config = config if config else {} self.__headers = headers if headers else {} self.__http_headers = {} self.__deadline = deadline self.__content_type = content_type self._request_url = request_url self._method = method self.__response_headers = {} self.__fn_format = fn_format self.__app_name = app_name self.__fn_name = fn_name self.__tracing_context = tracing_context if tracing_context else None log.log("request headers. gateway: {0} {1}" .format(self.__is_gateway(), headers)) if self.__is_gateway(): self.__headers = hs.decap_headers(headers, True) self.__http_headers = hs.decap_headers(headers, False)
def test_decap_headers_strip(): decap = headers.decap_headers( { "fn-http-h-Foo-Header": "v1", "fn-http-h-merge-header": ["v2"], "Foo-Header": "ignored", "merge-header": "v3", "other-header": "bad" }, False) assert decap == {"foo-header": "v1", "merge-header": ["v2"]}
async def process_response(fn_call_coro): new_headers = {} resp = await fn_call_coro for k, v in dict(resp.headers).items(): new_headers.update({k.lstrip(constants.FN_HTTP_PREFIX): v}) content = await resp.content.read() resp_headers = hs.decap_headers(resp.headers) status = int(resp.headers.get(constants.FN_HTTP_STATUS)) resp_headers.delete(constants.FN_HTTP_STATUS) return content, status, resp_headers
def test_decap_headers_merge(): decap = headers.decap_headers( { "fn-http-h-Foo-Header": "v1", "fn-http-h-merge-header": "v2", "fn-http-h-merge-Header": ["v3"], "Foo-Header": "ignored", "other-header": "bob" }, True) assert "foo-header" in decap assert decap["foo-header"] == "v1" assert "other-header" in decap assert decap["other-header"] == "bob" assert "merge-header" in decap assert set(decap["merge-header"]) == {"v2", "v3"}
def __init__(self, invoke_context: InvokeContext): self.__headers = hs.decap_headers(invoke_context.Headers()) self.__invoke_context = invoke_context self.__response_headers = hs.GoLikeHeaders({})