Skip to content

Commit

Permalink
Merge pull request #184 from lumapps/feat/allow-to-add-headers
Browse files Browse the repository at this point in the history
Feat/allow to add headers
  • Loading branch information
jssevestre committed Oct 4, 2022
2 parents 07d27bb + a664764 commit dce517a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lumapps/api/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __init__(
prune: bool = False,
no_verify: bool = False,
proxy_info: Optional[Dict[str, Any]] = None,
extra_http_headers: Optional[Dict] = None,
):
"""
Args:
Expand All @@ -72,7 +73,9 @@ def __init__(
self._token = None
self._endpoints = None
self._client = None
self._headers: dict = {}
self._headers: dict = {"x-lumapps-analytics": "off"}
if extra_http_headers:
self._headers.update(extra_http_headers)
if api_info is None:
api_info = {}
api_info.setdefault("name", LUMAPPS_NAME)
Expand Down
6 changes: 5 additions & 1 deletion lumapps/latest/client/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ def request(self, request: Request, **_: Any) -> Response:
request.method,
f"{self.organization_url}/{request.url.lstrip('/')}",
params=request.params,
headers={**request.headers, "User-Agent": "lumapps-sdk"},
headers={
**request.headers,
"User-Agent": "lumapps-sdk",
"x-lumapps-analytics": "off",
},
json=request.json,
)
return Response(
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ requests-oauthlib = "^1.3.0"

[tool.poetry.dev-dependencies]
flake8 = "^3.8.3"
importlib-metadata = "<5.0"
coverage = "^5.1"
pytest = "^6.0.2"
pytest-mock = "^3.3.1"
Expand Down
6 changes: 6 additions & 0 deletions tests/legacy/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ def dummy_get_content_by_slug(_, desired_slug, fields="id"):
slug = "first-project-items-are-due-1-goals-and-deliverables-2-project-members-3-due-dates-if-you-need"
new_slug = cli.get_available_slug(slug)
assert new_slug == slug + "-10"


def test_custom_headers():
headers = {"my-header": "on"}
cli = LumAppsClient("a", "b", token="FAKE", extra_http_headers=headers)
assert "my-header" in cli.client.headers

0 comments on commit dce517a

Please sign in to comment.