Set Cookie
This module provides an example of Set Cookie on http response for a particular client request.
- class callouts.python.extproc.example.set_cookie.service_callout_example.CalloutServerExample(*args: Any, **kwargs: Any)[source]
Bases:
CalloutServer
Example Set Cookie / Callout server.
For response header callouts we set a cookie providing a mutation to add a header ‘{Set-Cookie: cookie}’. This cookie is only set for callouts from certain clients, based on the presence of the ‘cookie-check’ header key.
- Usage:
To use this example callout server, instantiate the CalloutServerExample class and run the gRPC service.
- on_response_headers(headers: envoy.service.ext_proc.v3.external_processor_pb2.HttpHeaders, context: ServicerContext) → envoy.service.ext_proc.v3.external_processor_pb2.HeadersResponse[source]
Custom processor on response headers.
This method should set cookie on http response for a particular client callout.
- Parameters:
headers (service_pb2.HttpHeaders) – The HTTP headers received in the response.
context (ServicerContext) – The context object for the gRPC service.
- Returns:
The response containing the mutations to be applied to the response headers.
- Return type:
service_pb2.HeadersResponse
- callouts.python.extproc.example.set_cookie.service_callout_example.validate_header(http_headers: envoy.service.ext_proc.v3.external_processor_pb2.HttpHeaders) → str | None[source]
Validate if the incomming headers contain the ‘cookie-check’ header.
This function checks if the ‘cookie-check’ header is present in the headers and returns its raw value if found.
- Parameters:
http_headers (service_pb2.HttpHeaders) – Incomming http headers to check.
- Returns:
The raw value of the ‘cookie-check’ header if found, otherwise None.
- Return type:
str or None