Skip to content

Commit ac70d38

Browse files
dkolaseob
andauthored
[SHIP-768] Receive headers in invocations from proxy (#507)
Receive headers in the invocation context from the proxy. Depends on https://github.com/nludb/nludb/pull/603 Co-authored-by: Ted Benson <edward.benson@gmail.com>
1 parent 4ecd7f1 commit ac70d38

3 files changed

Lines changed: 38 additions & 0 deletions

File tree

src/steamship/invocable/invocable_request.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class InvocationContext(CamelModel):
3030
invocable_url: str = None
3131
invocable_owner_handle: Optional[str] = None
3232
workspace_handle: Optional[str] = None
33+
headers: Dict[str, str] = None
3334

3435

3536
class InvocableRequest(CamelModel):
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import json
2+
3+
from steamship.invocable import PackageService, get
4+
5+
6+
class EchoTestHeader(PackageService):
7+
@get("echo_test_header")
8+
def echo_test_header(self) -> str:
9+
return json.dumps(self.context.headers)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import json
2+
3+
import pytest
4+
import requests
5+
from steamship_tests import PACKAGES_PATH
6+
from steamship_tests.utils.deployables import deploy_package
7+
8+
from steamship import Steamship
9+
10+
11+
@pytest.mark.usefixtures("client")
12+
def test_instance_init_is_called_on_package(client: Steamship):
13+
demo_package_path = PACKAGES_PATH / "echo_test_header.py"
14+
15+
with deploy_package(client, demo_package_path) as (_, _, instance):
16+
url = instance.invocation_url + "/echo_test_header"
17+
response = requests.get(
18+
url,
19+
headers={
20+
"authorization": f"bearer {client.config.api_key.get_secret_value()}",
21+
"test1": "testValue1",
22+
"test2": "testValue2",
23+
},
24+
)
25+
result = json.loads(response.text)
26+
assert result is not None
27+
assert result["test1"] == "testValue1"
28+
assert result["test2"] == "testValue2"

0 commit comments

Comments
 (0)