From 6f7ae84650f7f96bf9c19e15e9303604d7d053fc Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 9 Jan 2013 23:17:52 -0400 Subject: [PATCH] webapp: Use IP address, rather than localhost since some systems may have configuration problems or other issues that prevent web browsers from connecting to the right localhost IP for the webapp. Tested on both ipv4 and ipv6 localhost. Url for the latter looks like: http://[::1]:50676 --- Assistant/Threads/WebApp.hs | 18 +++++++++--------- Utility/WebApp.hs | 6 +++--- debian/changelog | 3 +++ ...ot_::1_which_breaks_IPv6_enabled_hosts.mdwn | 3 +++ 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Assistant/Threads/WebApp.hs b/Assistant/Threads/WebApp.hs index 5ac36f6989..c4c9fa87a4 100644 --- a/Assistant/Threads/WebApp.hs +++ b/Assistant/Threads/WebApp.hs @@ -35,7 +35,7 @@ import Git import Yesod import Yesod.Static -import Network.Socket (PortNumber) +import Network.Socket (SockAddr) import Data.Text (pack, unpack) thisThread :: String @@ -67,14 +67,14 @@ webAppThread assistantdata urlrenderer noannex postfirstrun onstartup = thread $ ( return $ httpDebugLogger app , return app ) - runWebApp app' $ \port -> if noannex + runWebApp app' $ \addr -> if noannex then withTempFile "webapp.html" $ \tmpfile _ -> - go port webapp tmpfile Nothing + go addr webapp tmpfile Nothing else do let st = threadState assistantdata htmlshim <- runThreadState st $ fromRepo gitAnnexHtmlShim urlfile <- runThreadState st $ fromRepo gitAnnexUrlFile - go port webapp htmlshim (Just urlfile) + go addr webapp htmlshim (Just urlfile) where thread = NamedThread thisThread getreldir @@ -82,13 +82,13 @@ webAppThread assistantdata urlrenderer noannex postfirstrun onstartup = thread $ | otherwise = Just <$> (relHome =<< absPath =<< runThreadState (threadState assistantdata) (fromRepo repoPath)) - go port webapp htmlshim urlfile = do - let url = myUrl webapp port + go addr webapp htmlshim urlfile = do + let url = myUrl webapp addr maybe noop (`writeFileProtected` url) urlfile writeHtmlShim "Starting webapp..." url htmlshim maybe noop (\a -> a url htmlshim) onstartup -myUrl :: WebApp -> PortNumber -> Url -myUrl webapp port = unpack $ yesodRender webapp urlbase HomeR [] +myUrl :: WebApp -> SockAddr -> Url +myUrl webapp addr = unpack $ yesodRender webapp urlbase HomeR [] where - urlbase = pack $ "http://localhost:" ++ show port + urlbase = pack $ "http://" ++ show addr diff --git a/Utility/WebApp.hs b/Utility/WebApp.hs index d3bd523a82..51300c9cf1 100644 --- a/Utility/WebApp.hs +++ b/Utility/WebApp.hs @@ -54,14 +54,14 @@ runBrowser url env = boolSystemEnv cmd [Param url] env {- Binds to a socket on localhost, and runs a webapp on it. - - - An IO action can also be run, to do something with the port number, + - An IO action can also be run, to do something with the address, - such as start a web browser to view the webapp. -} -runWebApp :: Wai.Application -> (PortNumber -> IO ()) -> IO () +runWebApp :: Wai.Application -> (SockAddr -> IO ()) -> IO () runWebApp app observer = do sock <- localSocket void $ forkIO $ runSettingsSocket defaultSettings sock app - observer =<< socketPort sock + observer =<< getSocketName sock {- Binds to a local socket, selecting any free port. - diff --git a/debian/changelog b/debian/changelog index eceb47493b..2df17e2bcd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -6,6 +6,9 @@ git-annex (3.20130108) UNRELEASED; urgency=low * drop: Suggest using git annex move when numcopies prevents dropping a file. * webapp: Repo switcher filters out repos that do not exist any more (or are on a drive that's not mounted). + * webapp: Use IP address, rather than localhost, since some systems may + have configuration problems or other issues that prevent web browsers + from connecting to the right localhost IP for the webapp. -- Joey Hess Tue, 08 Jan 2013 12:37:38 -0400 diff --git a/doc/bugs/assistant_listens_on_127.0.0.1_not_::1_which_breaks_IPv6_enabled_hosts.mdwn b/doc/bugs/assistant_listens_on_127.0.0.1_not_::1_which_breaks_IPv6_enabled_hosts.mdwn index c1e84a760e..90034f7f57 100644 --- a/doc/bugs/assistant_listens_on_127.0.0.1_not_::1_which_breaks_IPv6_enabled_hosts.mdwn +++ b/doc/bugs/assistant_listens_on_127.0.0.1_not_::1_which_breaks_IPv6_enabled_hosts.mdwn @@ -25,3 +25,6 @@ I've tested this with: * chromium Iceweasel is the only one which correctly fell back to IPv4 and worked. + +> Ok, I've made it use the IP address in the URL. Ugly, but avoids +> whatever mess results in this behavior. [[done]] --[[Joey]]