def on_request_body()

in callouts/python/extproc/example/add_custom_response/service_callout_example.py [0:0]


  def on_request_body(self, body: service_pb2.HttpBody,
                      context: ServicerContext):
    """Custom processor on the request body.

    Args:
      body (service_pb2.BodyResponse): The HTTP body received in the request.
      context (ServicerContext): The context object for the gRPC service.

    Returns:
      service_pb2.BodyResponse: The response containing the mutations to be applied
      to the request body.
    """
    if callout_tools.body_contains(body, "bad-body"):
      callout_tools.deny_callout(context)
    if callout_tools.body_contains(body, 'mock'):
      return generate_mock_body_response()
    return callout_tools.add_body_mutation(body='replaced-body')