[Haskell-cafe] Two GET HTTP requests

Yusaku Hashimoto nonowarn at gmail.com
Tue Feb 9 00:41:53 EST 2010

Try to reinstall HTTP package also. I think your HTTP package is still
linked with old broken network package.

HTTP depends on network. And network is a binding for network API of
OS. These API is for C-language. When ghc builds such binding
packages, It runs gcc for some purpose. gcc thinks you need 64bit
binary (from SL, I believe.) and works for 64bit environment. But ghc
on Mac can only build 32bit binaries. So it causes the problem.

You can check if network package was correctly built by running this.
This takes a host name, and gets the root document of the host via
HTTP using a socket. Build and try `./this_program haskell.org`

import Network.Socket
import System.IO
import System.Environment

getAddr :: HostName -> IO AddrInfo
getAddr host = head `fmap`
               (getAddrInfo (Just defaultHints { addrSocketType = Stream })
                            (Just host)
                            (Just "http"))

connected :: HostName -> IO Socket
connected host = do
    addrinfo <- getAddr host
    sock <- socket (addrFamily addrinfo)
                   (addrSocketType addrinfo)
                   (addrProtocol addrinfo)
    connect sock (addrAddress addrinfo)
    return sock

httpGet :: HostName -> IO String
httpGet host = do
    h <- flip socketToHandle ReadWriteMode =<< connected host
    hSetBuffering h NoBuffering
    hPutStr h "GET / HTTP/1.0\r\n\r\n"
    hGetContents h

main = fmap head getArgs >>= httpGet >>= putStr

I should have mentioned them in my last mail. Sorry.

By the way, ghc-6.12 on Mac still can not build 64bit binaries. So
upgrading ghc won't solve it.


On Mon, Feb 8, 2010 at 12:50 AM, Chris Eidhof <chris at eidhof.nl> wrote:
> Thanks. Unfortunately, it didn't help. The thing that frustrates me is that it's quite hard to debug. I guess I'll upgrade my GHC to 6.12, hopefully that'll solve it.
> -chris
> On 7 feb 2010, at 16:07, Yusaku Hashimoto wrote:
>> Hello,
>> On Sat, Feb 6, 2010 at 2:51 AM, Chris Eidhof <chris at eidhof.nl> wrote:
>>> Approach 3: I used the simpleHTTP function from the HTTP package. This crashed, after I dug a little deeper into the code, it threw an error on calling the parseURI function (openFile: no such file exists). I installed the latest network package and upgraded my HTTP package, and the parseURI error went away. I felt like I was almost there, and tried the following:
>>>> simpleHTTP (getRequest "http://haskell.org")
>>> This failed with just the text "Bus error". I searched the HTTPBis git repository, but couldn't find the text "Bus error". I don't have a clue of how to fix this.
>> Try reinstall network package with `cabal install --reinstall
>> --hsc2hs-options="--cflag=-m32 --lflag=-m32"`.
>> See also: http://hackage.haskell.org/trac/ghc/ticket/3681
>> Hope this helps.
>> --nwn

More information about the Haskell-Cafe mailing list