mirror of
https://github.com/tensorflow/haskell.git
synced 2024-11-30 06:49:44 +01:00
Modifying tensorflow-mnist-input-data's setup to download MNIST through http proxy if necessary
Changing way to download MNIST dataset from Network.HTTP.simpleHTTP to Network.Browser.browse which allows to capture the environment's proxy.
This commit is contained in:
parent
0603a6987b
commit
39c68862ab
1 changed files with 8 additions and 3 deletions
|
@ -34,6 +34,7 @@ import System.Directory (doesFileExist)
|
||||||
import qualified Crypto.Hash as Hash
|
import qualified Crypto.Hash as Hash
|
||||||
import qualified Data.ByteString.Lazy as B
|
import qualified Data.ByteString.Lazy as B
|
||||||
import qualified Network.HTTP as HTTP
|
import qualified Network.HTTP as HTTP
|
||||||
|
import qualified Network.Browser as Browser
|
||||||
import qualified Network.URI as URI
|
import qualified Network.URI as URI
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
|
@ -65,9 +66,13 @@ httpDownload url outFile = do
|
||||||
let uri = fromMaybe
|
let uri = fromMaybe
|
||||||
(error ("Can't be: invalid URI " ++ url))
|
(error ("Can't be: invalid URI " ++ url))
|
||||||
(URI.parseURI url)
|
(URI.parseURI url)
|
||||||
result <- HTTP.simpleHTTP (HTTP.defaultGETRequest_ uri)
|
(_, rsp)
|
||||||
HTTP.getResponseCode result >>= \case
|
<- Browser.browse $ do
|
||||||
(2, 0, 0) -> HTTP.getResponseBody result >>= B.writeFile outFile
|
Browser.setAllowRedirects True -- handle HTTP redirects
|
||||||
|
Browser.setCheckForProxy True -- detect proxy if setted
|
||||||
|
Browser.request $ HTTP.defaultGETRequest_ uri
|
||||||
|
case HTTP.rspCode rsp of
|
||||||
|
(2, 0, 0) -> B.writeFile outFile $ HTTP.rspBody rsp
|
||||||
s -> error ( "Failed to download " ++ url ++ " error code " ++ show s
|
s -> error ( "Failed to download " ++ url ++ " error code " ++ show s
|
||||||
++ helpfulMessage
|
++ helpfulMessage
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue