Skip to content

Commit e99864a

Browse files
committed
Allow missing scheme in hydra url -fixes #95
1 parent 7774af5 commit e99864a

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

kuber-hydra/app/Websocket/SocketConnection.hs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ data AppConfig = AppConfig
3939

4040
createAppConfig :: String -> Maybe String -> Int -> ChainConnectInfo -> AppConfig
4141
createAppConfig rawUrl serverIp serverPort chainInfo =
42-
let (host, port) = getHydraIpAndPort rawUrl
42+
let normalizedUrl = normalizeHydraUrl rawUrl
43+
(host, port) = getHydraIpAndPort normalizedUrl
4344
scheme
44-
| any (`isPrefixOf` rawUrl) ["https://", "wss://"] = "https://"
45-
| any (`isPrefixOf` rawUrl) ["http://", "ws://"] = "http://"
45+
| any (`isPrefixOf` normalizedUrl) ["https://", "wss://"] = "https://"
46+
| any (`isPrefixOf` normalizedUrl) ["http://", "ws://"] = "http://"
4647
| otherwise = error $ "Invalid scheme in kuber-url: " ++ rawUrl ++ ". Expected one of ws://, wss://, http://, or https://"
4748
baseUrl = scheme ++ host ++ ":" ++ show port ++ "/"
4849
in AppConfig host port baseUrl serverIp serverPort chainInfo
@@ -60,7 +61,8 @@ getHydraIpAndPort url =
6061
| Just rest <- stripPrefix "https://" u = Just rest
6162
| otherwise = Nothing
6263

63-
mStripped = removeProtocol url
64+
normalizedUrl = normalizeHydraUrl url
65+
mStripped = removeProtocol normalizedUrl
6466
in
6567
case mStripped of
6668
Nothing -> error $ "Invalid URL: " ++ url ++ ". URL must start with ws://, wss://, http://, or https://"
@@ -76,6 +78,11 @@ getHydraIpAndPort url =
7678
"" -> (host, 8080)
7779
_ -> error $ "Invalid URL format: " ++ url
7880

81+
normalizeHydraUrl :: String -> String
82+
normalizeHydraUrl url
83+
| any (`isPrefixOf` url) ["ws://", "wss://", "http://", "https://"] = url
84+
| otherwise = "ws://" ++ url
85+
7986
hydraBaseUrl :: AppConfig -> String
8087
hydraBaseUrl = hydraApiBaseUrl
8188

0 commit comments

Comments
 (0)