christagger commented on issue #226:
URL:
https://github.com/apache/apisix-java-plugin-runner/issues/226#issuecomment-1383460144
here is my code, i want to calculate the request-response time :
```java
public class DemoFilter implements PluginFilter {
private final Logger logger = LoggerFactory.getLogger(DemoFilter.class);
@Override
public String name() {
return "DemoFilter";
}
@Override
public void filter(HttpRequest request, HttpResponse response,
PluginFilterChain chain) {
logger.info("DemoFilter is running");
// TODO : add a custom header "startTimestamp" here (or added in
another plugin's filter() method)
request.setHeader("startTimestamp",
String.valueOf(System.currentTimeMillis()));
chain.filter(request, response);
}
@Override
public void postFilter(PostRequest request, PostResponse response,
PluginFilterChain chain) {
// TODO : i want to get the custom header "startTimestamp" here, so
i can
// calculate the request-response time
chain.postFilter(request, response);
}
/**
* If you need to fetch some Nginx variables in the current plugin, you
will need to declare them in this function.
* @return a list of Nginx variables that need to be called in this
plugin
*/
@Override
public List<String> requiredVars() {
List<String> vars = new ArrayList<>();
vars.add("remote_addr");
vars.add("server_port");
return vars;
}
/**
* If you need to fetch request body in the current plugin, you will
need to return true in this function.
*/
@Override
public Boolean requiredBody() {
return true;
}
}
```
Or the more common scenario is: the custom header added in a pre-req-plugin
can be passed all along the request and can be acquired in every
post-resp-plugin postFilter() method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]