request_header_validator_interceptor.py
Go to the documentation of this file.
1 # Copyright 2017 gRPC authors.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 """Interceptor that ensures a specific header is present."""
15 
16 import grpc
17 
18 
19 def _unary_unary_rpc_terminator(code, details):
20 
21  def terminate(ignored_request, context):
22  context.abort(code, details)
23 
24  return grpc.unary_unary_rpc_method_handler(terminate)
25 
26 
28 
29  def __init__(self, header, value, code, details):
30  self._header = header
31  self._value = value
33 
34  def intercept_service(self, continuation, handler_call_details):
35  if (self._header,
36  self._value) in handler_call_details.invocation_metadata:
37  return continuation(handler_call_details)
38  else:
39  return self._terminator
grpc.unary_unary_rpc_method_handler
def unary_unary_rpc_method_handler(behavior, request_deserializer=None, response_serializer=None)
Definition: src/python/grpcio/grpc/__init__.py:1510
grpc.ServerInterceptor
Definition: src/python/grpcio/grpc/__init__.py:1373
request_header_validator_interceptor.RequestHeaderValidatorInterceptor._terminator
_terminator
Definition: request_header_validator_interceptor.py:32
request_header_validator_interceptor.RequestHeaderValidatorInterceptor
Definition: request_header_validator_interceptor.py:27
request_header_validator_interceptor._unary_unary_rpc_terminator
def _unary_unary_rpc_terminator(code, details)
Definition: request_header_validator_interceptor.py:19
request_header_validator_interceptor.RequestHeaderValidatorInterceptor.intercept_service
def intercept_service(self, continuation, handler_call_details)
Definition: request_header_validator_interceptor.py:34
request_header_validator_interceptor.RequestHeaderValidatorInterceptor._value
_value
Definition: request_header_validator_interceptor.py:31
request_header_validator_interceptor.RequestHeaderValidatorInterceptor._header
_header
Definition: request_header_validator_interceptor.py:30
request_header_validator_interceptor.RequestHeaderValidatorInterceptor.__init__
def __init__(self, header, value, code, details)
Definition: request_header_validator_interceptor.py:29


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:10