Callout Tools
Callout Tools
Library of commonly used methods within a callout server.
- callouts.python.extproc.service.callout_tools.add_body_mutation(body: str | None = None, clear_body: bool = False, clear_route_cache: bool = False) envoy.service.ext_proc.v3.external_processor_pb2.BodyResponse [source]
Generate a BodyResponse for incoming callouts.
body and clear_body are mutually exclusive, if body is set, clear_body will be ignored. If both body and clear_body are left as default, the incoming callout’s body will not be modified.
- Parameters:
body – Body text to replace the current body of the incomming callout.
clear_body – If true, will clear the body of the incomming callout.
clear_route_cache – If true, will enable clear_route_cache on the generated BodyResponse.
- Returns:
A configured body mutation response with the specified modifications.
- Return type:
BodyResponse
- callouts.python.extproc.service.callout_tools.add_command_line_args() ArgumentParser [source]
Adds command line args that can be passed to the CalloutServer constructor.
- Returns:
Configured argument parser with callout server options.
- Return type:
argparse.ArgumentParser
- callouts.python.extproc.service.callout_tools.add_header_mutation(add: list[tuple[str, str]] | None = None, remove: list[str] | None = None, clear_route_cache: bool = False, append_action: envoy.config.core.v3.base_pb2.HeaderValueOption.HeaderAppendAction | None = None) envoy.service.ext_proc.v3.external_processor_pb2.HeadersResponse [source]
Generate a HeadersResponse mutation for incoming callouts.
- Parameters:
add – A list of tuples representing headers to add or replace.
remove – List of header strings to remove from the callout.
clear_route_cache – If true, will enable clear_route_cache on the generated HeadersResponse.
append_action – Supported actions types for header append action.
- Returns:
A configured header mutation response with the specified modifications.
- Return type:
HeadersResponse
- callouts.python.extproc.service.callout_tools.body_contains(http_body: envoy.service.ext_proc.v3.external_processor_pb2.HttpBody, body: str) bool [source]
Check the body for the presence of a substring.
- Parameters:
body – Body substring to look for.
- Returns:
True if http_body contains expected_body, false otherwise.
- callouts.python.extproc.service.callout_tools.deny_callout(context, msg: str | None = None) None [source]
Denies a gRPC callout, optionally logging a custom message.
- Parameters:
context (grpc.ServicerContext) – The gRPC service context.
msg (str, optional) – Custom message to log before denying the callout. Also logged to warning. If no message is specified, defaults to “Callout DENIED.”.
- Raises:
grpc.StatusCode.PERMISSION_DENIED – Always raised to deny the callout.
- callouts.python.extproc.service.callout_tools.header_immediate_response(code: envoy.type.v3.http_status_pb2.StatusCode, headers: list[tuple[str, str]] | None = None, append_action: envoy.config.core.v3.base_pb2.HeaderValueOption.HeaderAppendAction | None = None) envoy.service.ext_proc.v3.external_processor_pb2.ImmediateResponse [source]
Creates an immediate HTTP response with specific headers and status code.
- Parameters:
code (StatusCode) – The HTTP status code to return.
headers – Optional list of tuples (header, value) to include in the response.
append_action – Optional action specifying how headers should be appended.
- Returns:
Configured immediate response with the specified headers and status code.
- Return type:
ImmediateResponse
- callouts.python.extproc.service.callout_tools.headers_contain(http_headers: envoy.service.ext_proc.v3.external_processor_pb2.HttpHeaders, key: str, value: str | None = None) bool [source]
Check the headers for a matching key value pair.
If no value is specified, only checks for the presence of the header key.
- Parameters:
http_headers – Headers to check.
key – Header key to find.
value – Header value to compare.
- Returns:
True if http_headers contains a match, false otherwise.