@lukasa Thanks for reply. I have a lot of blind moments in understanding of NIO proxy, but I try to figure out what flow we have.
ServerBootstrap pipeline contains:
- 1 HTTPResponseEncoder (outbound IN/OUT OutboundIn = HTTPServerResponsePart OutboundOut = IOData)
- 2 ByteToMessageHandler (InboundIn = ByteBuffer, InboundOut = Decoder.InboundOut, OutboundIn = Decoder.OutboundIn)
- 3 HTTPRequestDecoder (InboundOut = HTTPServerRequestPart)
- 4 HttpHttpsConnectHandler (duplex inbound IN, outbound IN/OUT)
- 5 GlueHandler2 (duplex inbound IN, outbound IN/OUT - Bytebuffer)
HttpHttpsConnectHandler detecs is it HTTP scheme or method CONNECT and create appropriate ClientBootstrap.
For HTTP we create ClientBootstrap and it pipeline contains:
-
1 HTTPRequestEncoder (OutboundIn = HTTPClientRequestPart, OutboundOut = IOData)
-
2 ByteToMessageHandler (InboundIn = ByteBuffer, InboundOut = Decoder.InboundOut, OutboundIn = Decoder.OutboundIn)
-
3 HTTPResponseDecoder (InboundOut = In HTTPClientResponsePart , OutboundIn = HTTPClientRequestPart)
-
4 GlueHandler1 (duplex inbound IN, outbound IN/OUT - Bytebuffer)
After ClientBootstrap connected to remote server, we put our data to GlueHandler2 (in server bootstrap) and it makes partnerWrite -> which invokes clinetBootsrap handlers to work. HttpHttpsConnectHandler InboundOut = HTTPClientRequestPart, GlueHandler1 get is as NIOAny and just forward it to ByteToMessageHandler (which wraps HTTPResponseDecoder) HTTPResponseDecoder OutboundIn = HTTPClientRequestPart.
For this moment, as i see, types corrrect we send HTTPClientRequestPart and get this type in HTTPResponseDecoder.
I dont find that ByteToMessageHandler has OutboundOut type, probably it can be the same as OutboundIn.
The last HTTPRequestEncoder OutboundIn = HTTPClientRequestPart OutboundOut = IOData
As you mentioned above for some reasons Decoder gets HTTPServerRequestPart but want HTTPClientRequestPart.
You also write that sometimes GluHandler can get FileRegion type, why is this can happened? May be on try to get some special resources?
HttpHttpsConnectHandler for HTTP ClinetBootstrap doesnt remove any handlers from pipeline after connection success.
Does the problem in HTTP bottstrap? What bootstrap should be transformed by the (removeHandler)? May be smth wrong in my understanding of how flow should be?
And the one more crash with the same errro appeared in
HttpHttpsConnectHandler
func channelRead(context: ChannelHandlerContext, data: NIOAny) {
switch self.upgradeState {
case .idle, .pendingConnection(head: _), .connected:
self.handleInitialMessage(context: context, data:self.unwrapInboundIn(data))
self.unwrapInboundIn(data))
Error NIO-ELT-#1 (4): Fatal error: tried to decode as type HTTPPart<HTTPRequestHead, ByteBuffer> but found IOData with contents ioData(IOData { ByteBuffer { readerIndex: 0, writerIndex: 813, readableBytes: 813, capacity: 2048, slice: _ByteBufferSlice { 0..<2048 }, storage: 0x0000000104846000 (2048 bytes) } })