Skip to content

Commit

Permalink
Add remoteAddress for socket
Browse files Browse the repository at this point in the history
  • Loading branch information
enums committed Jan 2, 2022
1 parent fc50e2e commit 1c29ffe
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Sources/Heze/Socket/HezeSocketHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import PerfectWebSockets
open class HezeSocketHandler: HezeHandler, WebSocketSessionHandler {

public var socket: WebSocket? = nil
public var remoteHost: String?
public var remotePort: UInt16?
public var buffer = [UInt8]()

open var socketProtocol: String? {
Expand All @@ -34,14 +36,26 @@ open class HezeSocketHandler: HezeHandler, WebSocketSessionHandler {
return
}
WebSocketHandler(handlerProducer: { (request, protocols) in
let handler: HezeSocketHandler?
if let socketProtocol = self.socketProtocol {
guard protocols.contains(socketProtocol) else {
return nil
}
return type(of: self).create(context: self.context)
#if os(macOS)
handler = Self.create(context: self.context)
#else
handler = type(of: self).create(context: self.context)
#endif
} else {
return type(of: self).create(context: self.context)
#if os(macOS)
handler = Self.create(context: self.context)
#else
handler = type(of: self).create(context: self.context)
#endif
}
handler?.remoteHost = req.remoteAddress.host
handler?.remotePort = req.remoteAddress.port
return handler
}).handleRequest(request: req, response: res)
}

Expand Down

0 comments on commit 1c29ffe

Please sign in to comment.