Add upgrade authorization (#55)
Former-commit-id: fc0fd8c3e86b05bf70b375fcd9003bfb3c3cef2f Former-commit-id: 5e9886504a259694b3f701facb3a157c58c51c08 [formerly 91dcf07282fdb8eb4509ece65e4319afc2e0e63a] [formerly 0e4ab369f6dccd4345abcb231dede9792c6da1b6 [formerly 08dd7bbfe8f0e83f4da3a5cd075829879ed7708e [formerly 08dd7bbfe8f0e83f4da3a5cd075829879ed7708e [formerly 08dd7bbfe8f0e83f4da3a5cd075829879ed7708e [formerly 110b575813ba5bc29f6781c186bc717b902b19e8]]]]] Former-commit-id: 246c512eb0079381e71025289263128d3276b033 [formerly 646016a7440f79a4cd780592673886d9fb56e666] Former-commit-id: 3566d8c6182750caecb4d12efa1b99f2907cefd0 Former-commit-id: ab0c88e833bdf4880ceb54e97631437365989730 Former-commit-id: 2a034de4c8ae116dbb9417959983e6efb219a4a3 Former-commit-id: 3b0808aae98269da1ee78f37c1843dcd2b1a7434 [formerly 2ee9122afbd141868e78bb428c41cd05f65ac134] Former-commit-id: 7272db885b47475f33ca39d9bdbe2191159664ff
This commit is contained in:
parent
97cc207e4d
commit
ce3a225dfc
3 changed files with 14 additions and 1 deletions
10
app/Main.hs
10
app/Main.hs
|
@ -31,6 +31,8 @@ data WsTunnel = WsTunnel
|
||||||
, verbose :: Bool
|
, verbose :: Bool
|
||||||
, quiet :: Bool
|
, quiet :: Bool
|
||||||
, pathPrefix :: String
|
, pathPrefix :: String
|
||||||
|
, wsTunnelCredentials
|
||||||
|
:: String
|
||||||
} deriving (Show, Data, Typeable)
|
} deriving (Show, Data, Typeable)
|
||||||
|
|
||||||
data WsServerInfo = WsServerInfo
|
data WsServerInfo = WsServerInfo
|
||||||
|
@ -61,6 +63,10 @@ cmdLine = WsTunnel
|
||||||
, pathPrefix = def &= explicit &= name "upgradePathPrefix"
|
, pathPrefix = def &= explicit &= name "upgradePathPrefix"
|
||||||
&= help "Use a specific prefix that will show up in the http path in the upgrade request. Useful if you need to route requests server side but don't have vhosts"
|
&= help "Use a specific prefix that will show up in the http path in the upgrade request. Useful if you need to route requests server side but don't have vhosts"
|
||||||
&= typ "String" &= groupname "Client options"
|
&= typ "String" &= groupname "Client options"
|
||||||
|
, wsTunnelCredentials
|
||||||
|
= def &= explicit &= name "upgradeCredentials"
|
||||||
|
&= help "Credentials for the Basic HTTP authorization type sent with the upgrade request."
|
||||||
|
&= typ "USER[:PASS]"
|
||||||
, proxy = def &= explicit &= name "p" &= name "httpProxy"
|
, proxy = def &= explicit &= name "p" &= name "httpProxy"
|
||||||
&= help "If set, will use this proxy to connect to the server" &= typ "USER:PASS@HOST:PORT"
|
&= help "If set, will use this proxy to connect to the server" &= typ "USER:PASS@HOST:PORT"
|
||||||
, soMark = def &= explicit &= name "soMark"
|
, soMark = def &= explicit &= name "soMark"
|
||||||
|
@ -220,6 +226,7 @@ runApp cfg serverInfo
|
||||||
, proxySetting = parseProxyInfo (proxy cfg)
|
, proxySetting = parseProxyInfo (proxy cfg)
|
||||||
, useSocks = False
|
, useSocks = False
|
||||||
, upgradePrefix = pathPrefix cfg
|
, upgradePrefix = pathPrefix cfg
|
||||||
|
, upgradeCredentials = BC.pack $ wsTunnelCredentials cfg
|
||||||
, udpTimeout = Main.udpTimeout cfg
|
, udpTimeout = Main.udpTimeout cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,6 +243,7 @@ runApp cfg serverInfo
|
||||||
, proxySetting = parseProxyInfo (proxy cfg)
|
, proxySetting = parseProxyInfo (proxy cfg)
|
||||||
, useSocks = False
|
, useSocks = False
|
||||||
, upgradePrefix = pathPrefix cfg
|
, upgradePrefix = pathPrefix cfg
|
||||||
|
, upgradeCredentials = BC.pack $ wsTunnelCredentials cfg
|
||||||
, udpTimeout = Main.udpTimeout cfg
|
, udpTimeout = Main.udpTimeout cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,6 +260,7 @@ runApp cfg serverInfo
|
||||||
, proxySetting = parseProxyInfo (proxy cfg)
|
, proxySetting = parseProxyInfo (proxy cfg)
|
||||||
, useSocks = False
|
, useSocks = False
|
||||||
, upgradePrefix = pathPrefix cfg
|
, upgradePrefix = pathPrefix cfg
|
||||||
|
, upgradeCredentials = BC.pack $ wsTunnelCredentials cfg
|
||||||
, udpTimeout = Main.udpTimeout cfg
|
, udpTimeout = Main.udpTimeout cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,5 +277,6 @@ runApp cfg serverInfo
|
||||||
, proxySetting = parseProxyInfo (proxy cfg)
|
, proxySetting = parseProxyInfo (proxy cfg)
|
||||||
, useSocks = True
|
, useSocks = True
|
||||||
, upgradePrefix = pathPrefix cfg
|
, upgradePrefix = pathPrefix cfg
|
||||||
|
, upgradeCredentials = BC.pack $ wsTunnelCredentials cfg
|
||||||
, udpTimeout = Main.udpTimeout cfg
|
, udpTimeout = Main.udpTimeout cfg
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,8 @@ tunnelingClientP cfg@TunnelSettings{..} app conn = onError $ do
|
||||||
debug "Oppening Websocket stream"
|
debug "Oppening Websocket stream"
|
||||||
|
|
||||||
stream <- connectionToStream conn
|
stream <- connectionToStream conn
|
||||||
ret <- WS.runClientWithStream stream serverHost (toPath cfg) WS.defaultConnectionOptions [] run
|
let headers = if not (null upgradeCredentials) then [("Authorization", "Basic " <> B64.encode upgradeCredentials)] else []
|
||||||
|
ret <- WS.runClientWithStream stream serverHost (toPath cfg) WS.defaultConnectionOptions headers run
|
||||||
|
|
||||||
debug "Closing Websocket stream"
|
debug "Closing Websocket stream"
|
||||||
return ret
|
return ret
|
||||||
|
|
|
@ -77,6 +77,8 @@ data TunnelSettings = TunnelSettings
|
||||||
, useTls :: Bool
|
, useTls :: Bool
|
||||||
, useSocks :: Bool
|
, useSocks :: Bool
|
||||||
, upgradePrefix :: String
|
, upgradePrefix :: String
|
||||||
|
, upgradeCredentials
|
||||||
|
:: ByteString
|
||||||
, udpTimeout :: Int
|
, udpTimeout :: Int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue