We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hello guys,
how to update httpContent in filters ?
my code is here, it works if i change the capacity shorter or stay unchanged, but not works if i change it bigger. what's the problem?
`
private class MyHttpFiltersSourceAdapter extends HttpFiltersSourceAdapter { @Override public HttpFilters filterRequest(HttpRequest originalRequest, ChannelHandlerContext clientCtx) { Log.v(TAG, "request: " + originalRequest.hashCode() + " uri: " + originalRequest.getUri() + ", method: " + originalRequest.getMethod()); if (originalRequest.getMethod() == HttpMethod.GET || originalRequest.getMethod() == HttpMethod.HEAD || originalRequest.getMethod() == HttpMethod.POST) { return new MyHttpFilter(originalRequest, clientCtx); } } } private class MyHttpFilter extends HttpFiltersAdapter { @Override public HttpResponse clientToProxyRequest(HttpObject httpObject) { if (httpObject instanceof LastHttpContent) { LastHttpContent httpContent = (LastHttpContent) httpObject; ByteBuf byteBuffer = httpContent.content().slice(); byte[] body = new byte[byteBuffer.readableBytes()]; byteBuffer.getBytes(0, body); String contentString = new String(body, io.netty.util.CharsetUtil.UTF_8); String newBody = "111111111111111111"; try { int idx = byteBufIdx(byteBuffer, 0); if (idx >= 0) { int writerIndex = byteBuffer.writerIndex(); int readSize = byteBuffer.readableBytes(); Log.d(TAG, "before update readable " + readSize + " writeidx " + byteBuffer.writerIndex()); ByteBuf bodyContent = Unpooled.copiedBuffer(newBody, io.netty.util.CharsetUtil.UTF_8); int newSize = bodyContent.readableBytes(); // tricky: use internal api to avoid length check int innerCap = byteBuffer.unwrap().capacity(); byteBuffer.unwrap().capacity(innerCap + newSize - readSize); byteBuffer.unwrap().setBytes(idx, bodyContent, 0, newSize); // update outter index&cap int cc = byteBufAdjustCapacity(byteBuffer, newSize - readSize); byteBuffer.writerIndex(writerIndex - readSize + newSize); Log.d(TAG, "update post content " + contentString + " to " + newBody + " new cap " + cc + " writeidx " + byteBuffer.writerIndex()); byte[] readout = new byte[byteBuffer.readableBytes()]; byteBuffer.getBytes(byteBuffer.readerIndex(), readout); Log.d(TAG, "bytebuf: " + new String(readout, io.netty.util.CharsetUtil.UTF_8)); } } catch (Exception e) { e.printStackTrace(); } } } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
hello guys,
how to update httpContent in filters ?
my code is here, it works if i change the capacity shorter or stay unchanged, but not works if i change it bigger. what's the problem?
`
`
The text was updated successfully, but these errors were encountered: