logo
down
shadow

Setting grpc metadata in http request


Setting grpc metadata in http request

By : Greling
Date : November 27 2020, 01:01 AM
With these it helps The trick here is using a custom incoming header matcher. You can see in the source code or grpc-gatway, that there is a WithIncomingHeaderMatcher that transforms incoming HTTP headers into metadata passed into the context (used later on by gRPC server handlers). By default it supports a set of so-called permanent HTTP headers which are passed as they are (so eg. Authorization header will come up as Authorization in the context), or you need to prefix your custom headers with a specific prefix, Grpc-Metadata-, see its usage here. In this case, Grpc-Metadata-Your-Name HTTP header will come up as Your-Name field in the metadata.
Again, if this is too problematic for you and you with to be able to pass eg. X-User-Id or any custom formatted headers into your app, you need to set up a custom header matcher. I would recommend to handle your headers explicitly and then fallback onto the default one (works great if you then update your dependencies and some new permanentHTTPHeader is added:
code :
    func headerMatcher(header string) (string, bool) {
        if header == "X-User-Id" {
            return "x-user-id", true
        }
        return runtime.DefaultHeaderMatcher(header)
    }


Share : facebook icon twitter icon
WCF The request failed with http status 400 bad request. Metadata contains a reference that cannot be resolved: http://l

WCF The request failed with http status 400 bad request. Metadata contains a reference that cannot be resolved: http://l


By : Lucius of Phoenix
Date : March 29 2020, 07:55 AM
I hope this helps you . When I browsed to http:localhost/MyService.svc, I was presented with the following error:
code :
An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.InvalidOperationException: An exception was thrown in a call to a WSDL export extension: System.ServiceModel.Description.DataContractSerializerOperationBehavior
 contract: http://tempuri.org/:IAdministrationService ----> System.InvalidOperationException: The IMyService1.UpdatePartner operation references a message element [http://tempuri.org/:UpdatePartner] that has already been exported from the IMyService2.UpdatePartner operation. You can change the name of one of the operations by changing the method name or using the Name property of OperationContractAttribute. Alternatively, you can control the element name in greater detail using the MessageContract programming model.
How to get client ip from request metadata with grpc-java

How to get client ip from request metadata with grpc-java


By : ZerOTanK
Date : March 29 2020, 07:55 AM
this will help Client IP is not provided in Metadata. But you can call ServerCall.attributes() and get the Grpc.TRANSPORT_ATTR_REMOTE_ADDR.
Please note that the API is unstable and may change.
How do I access request metadata for a java grpc service I am defining?

How do I access request metadata for a java grpc service I am defining?


By : Anu
Date : March 29 2020, 07:55 AM
To fix the issue you can do Use a ServerInterceptor and then propagate the identity via Context. This allows you to have a central policy for authentication.
The interceptor can retrieve the identity from Metadata headers. It should then validate the identity. The validated identity can then be communicated to the application (i.e., testHello) via io.grpc.Context:
code :
/** Interceptor that validates user's identity. */
class MyAuthInterceptor implements ServerInterceptor {
  public static final Context.Key<Object> USER_IDENTITY
      = Context.key("identity"); // "identity" is just for debugging

  @Override
  public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
      ServerCall<ReqT, RespT> call,
      Metadata headers,
      ServerCallHandler<ReqT, RespT> next) {
    // You need to implement validateIdentity
    Object identity = validateIdentity(headers);
    if (identity == null) { // this is optional, depending on your needs
      // Assume user not authenticated
      call.close(Status.UNAUTENTICATED.withDescription("some more info"),
                 new Metadata());
      return new ServerCall.Listener() {};
    }
    Context context = Context.current().withValue(USER_IDENTITY, identity);
    return Contexts.interceptCall(context, call, headers, next);
  }
}

public class TestImpl extends TestServiceGrpc.TestServiceImplBase {
  @Override
  public void testHello(TestRequest req, StreamObserver<TestResponse> responseObserver) {
    // Access to identity.
    Object identity = MyAuthInterceptor.USER_IDENTITY.get();
    ...
  }
}

// Need to use ServerInterceptors to enable the interceptor
Server server = ServerBuilder.forPort(PORT)
    .addService(ServerInterceptors.intercept(new TestImpl(),
        new MyAuthInterceptor()))
    .build()
    .start();
gRPC & HTTP servers on GKE Ingress failing healthcheck for gRPC backend

gRPC & HTTP servers on GKE Ingress failing healthcheck for gRPC backend


By : user2801011
Date : March 29 2020, 07:55 AM
Does that help Editing the health check to point to the readiness probe's path and changed the port to the one of the HTTP back-end fixed this issue (look for the port in the HTTP back-end's health check. it is the NodePort's.). It runs know without any issues.
Using the same health check for the gRPC back-end as for the HTTP back-end did not work, it was reset back to its own health check. Even deleting the gRPC back-end's health check did not help, it was recreated. Only editing it to use a different port and path has helped.
How to send trailing metadata from python gRPC service to grpc-web client?

How to send trailing metadata from python gRPC service to grpc-web client?


By : user2893664
Date : March 29 2020, 07:55 AM
Hope that helps Before calling method set_trailing_metadata, you need to call send_initial_metadata with same medatdata keys but any values.
In my case it will looks like this:
code :
class Greeter(helloworld_pb2_grpc.GreeterServicer):
    def SayHello(self, request, context):
        context.send_initial_metadata((
            ('checksum', ''),
            ('retry', ''),
        ))
        context.set_trailing_metadata((
            ('checksum', 'I agree'),
            ('retry', 'false'),
        ))
        return helloworld_pb2.HelloReply(message='Hello, %s!' % request.name)
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org