Request interceptor access to message body?


I’m trying to write an interceptor to add a custom header for authentication to our backend api’s.
To calculate the header, I need the following caller fields :
method (post/get/delete/etc)
body (as string/json etc)

I am starting with the Java sample (tyk-plugin-demo-java), but cannot see a way to access the http method (get/put/post/delete) or the mime type.

I am overriding as follows, but hardcoding for now :

 CoprocessObject.Object MyPreHook(CoprocessObject.Object request) {
    CoprocessObject.Object.Builder builder = request.toBuilder();
    String body = request.getRequest().getBody();
    String path = request.getRequest().getUrl();
    // TODO - how do we know if this is a GET or a POST?
    String method = "GET";
    String mime = "application/json";

Could anyone suggest how to unwrap this?


The method isn’t currently passed through to the middleware (it’s a known issue). As for the mime type, this will be available in the headers map.

The getters and setters for the object sent to the gRPC server are defined here I believe (I’m not a Java dev btw):