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 aaddaf1 commit 1c5cf54
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 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 @@ -38,22 +40,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
}
#if os(macOS)
return Self.create(context: self.context)
handler = Self.create(context: self.context)
#else
return type(of: self).create(context: self.context)
handler = type(of: self).create(context: self.context)
#endif
} else {
#if os(macOS)
return Self.create(context: self.context)
handler = Self.create(context: self.context)
#else
return type(of: self).create(context: self.context)
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 1c5cf54

Please sign in to comment.