use of io.gravitee.policy.api.annotations.OnRequestContent in project gravitee-gateway by gravitee-io.
the class OverrideRequestContentPolicy method onRequestContent.
@OnRequestContent
public ReadWriteStream onRequestContent(Request request) {
return new BufferedReadWriteStream() {
@Override
public SimpleReadWriteStream<Buffer> write(Buffer content) {
// We dot want to get the request content, skipping
return this;
}
@Override
public void end() {
Buffer content = Buffer.buffer(STREAM_POLICY_CONTENT);
request.headers().set(HttpHeaders.CONTENT_LENGTH, Integer.toString(content.length()));
// Write content
super.write(content);
// Mark the end of content
super.end();
}
};
}
use of io.gravitee.policy.api.annotations.OnRequestContent in project gravitee-gateway by gravitee-io.
the class TransformRequestContentPolicy method onRequestContent.
@OnRequestContent
public ReadWriteStream onRequestContent(Request request, ExecutionContext executionContext) {
return new BufferedReadWriteStream() {
Buffer buffer = Buffer.buffer();
@Override
public SimpleReadWriteStream<Buffer> write(Buffer content) {
// We dot want to get the request content, skipping
buffer.appendBuffer(content);
return this;
}
@Override
public void end() {
String content = executionContext.getTemplateEngine().convert(buffer.toString());
Buffer contentBuf = Buffer.buffer(content);
request.headers().set(HttpHeaders.CONTENT_LENGTH, Integer.toString(contentBuf.length()));
// Write content
super.write(contentBuf);
// Mark the end of content
super.end();
}
};
}
Aggregations