Reputation: 1243
I have used Connect Proxy with iOS's NEPacketTunnelProvider to set up a local proxy server and it works great!
However, I need some help to achieve my specific requirements. I have a remote proxy server running (e.g., 1.2.3.4:443), and my remote proxy server expects CONNECT requests along with additional headers, such as an auth-token. Upon receiving the CONNECT request with these headers, the remote proxy server responds with 200 OK, and the subsequent flow should continue.
In the current example provided by the plugin, I noticed the glue function is responsible for responding with 200 OK to the CONNECT request. I’d like to override this behavior so that the CONNECT request is sent to my remote proxy server along with the required headers.
Current Implementation
private func glue(_ peerChannel: Channel, context: ChannelHandlerContext) {
let headers = HTTPHeaders([("Content-Length", "0")])
let head = HTTPResponseHead(version: .init(major: 1, minor: 1), status: .ok, headers: headers)
context.write(self.wrapOutboundOut(.head(head)), promise: nil)
context.writeAndFlush(self.wrapOutboundOut(.end(nil)), promise: nil)
self.removeEncoder(context: context)
let (localGlue, peerGlue) = GlueHandler.matchedPair()
// rest of glue functionality
}
Expcted Implementation
private func glue(_ peerChannel: Channel, context: ChannelHandlerContext) {
//update the connect request received in local server with additonal headers
//send it to remote proxy server
//write the response from remote server to browser
//receive the client hello from local server and send it to remote proxy server
//receive the server hello from remote server and write it to browser
// glue local channel and the peer channel together.
// rest of glue functionality
}
I have posted the same questions in forums.swift.org and got a feed back from the community and tried some of the approaches and added the comment over there for further help.
I’d appreciate any guidance or pointers on how to accomplish this. Thank you in advance for your support!
Upvotes: 0
Views: 34