Add Custom Response

This module provides an example of Add Custom Response.

class callouts.python.extproc.example.add_custom_response.service_callout_example.CalloutServerExample(*args: Any, **kwargs: Any)[source]

Bases: CalloutServer

Example callout server.

On a request header callout we check if it contains a header called ‘{mock:}’, if yes then it will generate a mock response, otherwise it will follow the standard flow and add a header ‘{header-request: request}’. On response header callouts, we respond with a mutation to add the header ‘{header-response: response}’.

On a request body callout we check if it contains in the body ‘mock’, if yes then it will generate a mock response, otherwise it will follow the standard flow and provide a mutation to replace the body with ‘replaced-body’. On response body callouts we send a mutation to replace the body with ‘new-body’.

On header callouts, deny and close the connection when containing the header ‘bad-header’. On body callouts, deny and close the connection when containing the body substring ‘bad-body’.

on_request_body(body: envoy.service.ext_proc.v3.external_processor_pb2.HttpBody, context: ServicerContext)[source]

Custom processor on the request body.

Parameters:
  • body (service_pb2.BodyResponse) – The HTTP body received in the request.

  • context (ServicerContext) – The context object for the gRPC service.

Returns:

The response containing the mutations to be applied to the request body.

Return type:

service_pb2.BodyResponse

on_request_headers(headers: envoy.service.ext_proc.v3.external_processor_pb2.HttpHeaders, context: ServicerContext)[source]

Custom processor on request headers.

Parameters:
  • headers (service_pb2.HttpHeaders) – The HTTP headers received in the request.

  • context (ServicerContext) – The context object for the gRPC service.

Returns:

The response containing the mutations to be applied to the request headers.

Return type:

service_pb2.HeadersResponse

on_response_body(body: envoy.service.ext_proc.v3.external_processor_pb2.HttpBody, context: ServicerContext)[source]

Custom processor on the response body.

Parameters:
  • body (service_pb2.BodyResponse) – The HTTP body 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 body.

Return type:

service_pb2.BodyResponse

on_response_headers(headers: envoy.service.ext_proc.v3.external_processor_pb2.HttpHeaders, context: ServicerContext)[source]

Custom processor on response headers.

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.add_custom_response.service_callout_example.generate_mock_body_response()[source]

Generate mock body response.

callouts.python.extproc.example.add_custom_response.service_callout_example.generate_mock_header_response()[source]

Generate mock header response.