tomwojcik/starlette-context

Enforce that if request/correlation id provided, it must be a UUID otherwise generate new

derekbekoe opened this issue · 1 comments

Issue
Currently, any value is accepted.

Expectation
Only UUIDs should be accepted.

The could be implemented with a new kwarg on the Plugins so this isn't a breaking change for any users who currently accept request values that are not UUIDs.

Relevant source code

async def extract_value_from_header_by_key(
self, request: Request
) -> Optional[str]:
await super(
CorrelationIdPlugin, self
).extract_value_from_header_by_key(request)
if self.value is None:
self.value = uuid.uuid4().hex
return self.value

Happy to submit a PR if needed.

Makes sense.

Feel free to open a PR or I'll do that myself over the weekend.