use of io.gravitee.gateway.api.buffer.Buffer 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