Commit da3788ce authored by Andrew Gibiansky's avatar Andrew Gibiansky

Hoogle updated to use HTTPS, closes #311

parent 4eca3f2c
...@@ -71,7 +71,8 @@ library ...@@ -71,7 +71,8 @@ library
hlint >=1.9 && <2.0, hlint >=1.9 && <2.0,
haskell-src-exts ==1.16.*, haskell-src-exts ==1.16.*,
hspec -any, hspec -any,
HTTP == 4000.2.*, http-client == 0.4.*,
http-client-tls == 0.2.*,
HUnit -any, HUnit -any,
MissingH >=1.2, MissingH >=1.2,
mtl >=2.1, mtl >=2.1,
...@@ -166,7 +167,6 @@ Test-Suite hspec ...@@ -166,7 +167,6 @@ Test-Suite hspec
hlint >=1.9 && <2.0, hlint >=1.9 && <2.0,
haskell-src-exts ==1.15.*, haskell-src-exts ==1.15.*,
hspec -any, hspec -any,
HTTP -any,
HUnit -any, HUnit -any,
MissingH >=1.2, MissingH >=1.2,
mtl >=2.1, mtl >=2.1,
......
...@@ -9,11 +9,11 @@ module IHaskell.Eval.Hoogle ( ...@@ -9,11 +9,11 @@ module IHaskell.Eval.Hoogle (
import ClassyPrelude hiding (last, span, div) import ClassyPrelude hiding (last, span, div)
import Text.Printf import Text.Printf
import Network.HTTP import Network.HTTP.Client
import Network.HTTP.Client.TLS
import Data.Aeson import Data.Aeson
import Data.String.Utils import Data.String.Utils
import Data.List (elemIndex, (!!), last) import Data.List (elemIndex, (!!), last)
import Control.Monad (guard)
import qualified Data.ByteString.Lazy.Char8 as Char import qualified Data.ByteString.Lazy.Char8 as Char
...@@ -58,14 +58,14 @@ instance FromJSON HoogleResponse where ...@@ -58,14 +58,14 @@ instance FromJSON HoogleResponse where
-- message or the successful JSON result. -- message or the successful JSON result.
query :: String -> IO (Either String String) query :: String -> IO (Either String String)
query str = do query str = do
let request = getRequest $ queryUrl str request <- parseUrl $ queryUrl str
response <- simpleHTTP request response <- try $ withManager tlsManagerSettings $ httpLbs request
return $ case response of return $ case response of
Left err -> Left $ show err Left err -> Left $ show (err :: SomeException)
Right resp -> Right $ rspBody resp Right resp -> Right $ Char.unpack $ responseBody resp
where where
queryUrl :: String -> String queryUrl :: String -> String
queryUrl = printf "http://www.haskell.org/hoogle/?hoogle=%s&mode=json" . urlEncode queryUrl = printf "https://www.haskell.org/hoogle/?hoogle=%s&mode=json"
-- | Search for a query on Hoogle. -- | Search for a query on Hoogle.
-- Return all search results. -- Return all search results.
...@@ -156,6 +156,12 @@ renderSelf string loc ...@@ -156,6 +156,12 @@ renderSelf string loc
span "hoogle-class" (link loc $ extractClass string) ++ span "hoogle-class" (link loc $ extractClass string) ++
packageSub package packageSub package
| startswith "data" string
= let package = extractPackageName loc in
dat ++ " " ++
span "hoogle-class" (link loc $ extractData string) ++
packageSub package
| otherwise | otherwise
= let [name, args] = split "::" string = let [name, args] = split "::" string
package = extractPackageName loc package = extractPackageName loc
...@@ -170,9 +176,11 @@ renderSelf string loc ...@@ -170,9 +176,11 @@ renderSelf string loc
extractPackage = strip . replace "package" "" extractPackage = strip . replace "package" ""
extractModule = strip . replace "module" "" extractModule = strip . replace "module" ""
extractClass = strip . replace "class" "" extractClass = strip . replace "class" ""
extractData = strip . replace "data" ""
pkg = span "hoogle-head" "package" pkg = span "hoogle-head" "package"
mod = span "hoogle-head" "module" mod = span "hoogle-head" "module"
cls = span "hoogle-head" "class" cls = span "hoogle-head" "class"
dat = span "hoogle-head" "data"
unicodeReplace :: String -> String unicodeReplace :: String -> String
unicodeReplace = unicodeReplace =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment