Skip to content

Commit

Permalink
Add Cache-Control header to get configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
jschlyter committed Dec 22, 2024
1 parent 2c431df commit 01016ae
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions nodeman/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ async def renew_node(
async def get_node_configuration(
name: str,
request: Request,
response: Response,
) -> NodeConfiguration:
"""Get node configuration"""

Expand All @@ -369,4 +370,8 @@ async def get_node_configuration(

node_configurations_requested.add(1)

# Cache response for 5 minutes
max_age = request.app.settings.nodes.configuration_ttl
response.headers["Cache-Control"] = f"public, max-age={max_age}"

return res
1 change: 1 addition & 0 deletions nodeman/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class NodesSettings(BaseModel):
trusted_jwks: FilePath | None = Field(default=None)
mqtt_broker: MqttUrl = Field(default="mqtt://localhost")
mqtt_topics: dict[str, str] = Field(default={})
configuration_ttl: int = Field(default=300)


class User(BaseModel):
Expand Down
1 change: 1 addition & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def _test_enroll(data_key: JWK, x509_key: PrivateKey, requested_name: str | None
node_information = response.json()
print(json.dumps(node_information, indent=4))
assert node_information["name"] == name
assert response.headers.get("Cache-Control") is not None

#####################
# Get node public key
Expand Down

0 comments on commit 01016ae

Please sign in to comment.