Open weissi opened 4 years ago
more hacky but newer patch for this
diff --git a/Package.swift b/Package.swift
index f72de84..d572ea0 100644
--- a/Package.swift
+++ b/Package.swift
@@ -39,6 +39,7 @@ let package = Package(
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "NIOPosix", package: "swift-nio"),
+ .product(name: "NIOExtras", package: "swift-nio-extras"),
.product(name: "NIOHTTP1", package: "swift-nio"),
.product(name: "NIOConcurrencyHelpers", package: "swift-nio"),
.product(name: "NIOHTTP2", package: "swift-nio-http2"),
diff --git a/Sources/AsyncHTTPClient/ConnectionPool/HTTPConnectionPool+Factory.swift b/Sources/AsyncHTTPClient/ConnectionPool/HTTPConnectionPool+Factory.swift
index 1444df9..bd57a18 100644
--- a/Sources/AsyncHTTPClient/ConnectionPool/HTTPConnectionPool+Factory.swift
+++ b/Sources/AsyncHTTPClient/ConnectionPool/HTTPConnectionPool+Factory.swift
@@ -20,6 +20,8 @@ import NIOPosix
import NIOSOCKS
import NIOSSL
import NIOTLS
+import NIOExtras
+import Foundation
#if canImport(Network)
import NIOTransportServices
#endif
@@ -448,6 +450,17 @@ extension HTTPConnectionPool.ConnectionFactory {
.tlsOptions(options)
.channelInitializer { channel in
do {
+ let fileSink = try! NIOWritePCAPHandler.SynchronizedFileSink.fileSinkWritingToFile(path: "/tmp/packets-nw-\(sslServerHostname ?? "unknown")-\(UUID())-\(getpid())-\(Date()).pcap",
+ errorHandler: { error in
+ logger.error("ouch: \(error)")
+ })
+
+ try sync.addHandler(NIOWritePCAPHandler(mode: .client,
+ fileSink: fileSink.write(buffer:)))
+ channel.closeFuture.whenComplete { _ in
+ try! fileSink.syncClose()
+ }
+
try channel.pipeline.syncOperations.addHandler(HTTPClient.NWErrorHandler())
try channel.pipeline.syncOperations.addHandler(NWWaitingHandler(requester: requester, connectionID: connectionID))
// we don't need to set a TLS deadline for NIOTS connections, since the
@@ -485,6 +498,16 @@ extension HTTPConnectionPool.ConnectionFactory {
try sync.addHandler(sslHandler)
try sync.addHandler(tlsEventHandler)
+ let fileSink = try! NIOWritePCAPHandler.SynchronizedFileSink.fileSinkWritingToFile(path: "/tmp/packets-\(sslServerHostname ?? "unknown")-\(UUID())-\(getpid())-\(Date()).pcap",
+ errorHandler: { error in
+ logger.error("ouch: \(error)")
+ })
+
+ try sync.addHandler(NIOWritePCAPHandler(mode: .client,
+ fileSink: fileSink.write(buffer:)))
+ channel.closeFuture.whenComplete { _ in
+ try! fileSink.syncClose()
+ }
return channel.eventLoop.makeSucceededVoidFuture()
} catch {
return channel.eventLoop.makeFailedFuture(error)
for debugging purposes, we should offer an option to switch on plain text .pcap recording.
It should be very clear that it's for debugging because
NIOWritePCAPHandler.SynchronisedFileSink
blocks the event loop (we could write an async file sink ofc)...A pretty terrible patch that can serve as example (but not the final impl ofc) is here: