Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Getting warp and blaze to like each other (Adrian May)


----------------------------------------------------------------------

Message: 1
Date: Tue, 9 Jul 2013 16:44:59 +0800
From: Adrian May <[email protected]>
Subject: [Haskell-beginners] Getting warp and blaze to like each other
To: "[email protected]" <[email protected]>
Message-ID:
        <cad-ubzfu2wbvzwi8f3t4_zyywsh9ue4kbgzfixanubum8ph...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi All,

I just cobbled together the code below from a couple of samples, but got
the types matched up by trial and error. I don't really understand when
things are getting converted between lazy, strict, utf8, ascii, etc. I
don't want ascii in the served page at all. Is it optimal?

TIA,
Adrian

{-# LANGUAGE OverloadedStrings #-}

module Main where

import Network.Wai (Application, Response (ResponseBuilder))
import Network.HTTP.Types (status200)
import Network.HTTP.Types.Header (hContentType, hContentLength,
hConnection)
import Network.Wai.Handler.Warp (run)
import Blaze.ByteString.Builder (fromByteString, fromLazyByteString)
import qualified Data.ByteString.Char8 as BS (pack, length)

import qualified Text.Blaze.Html5 as H
import qualified Text.Blaze.Html5.Attributes as A
import Text.Blaze.Html.Renderer.Utf8

import qualified Data.ByteString.Lazy as LB

application:: Application
application _ = return $
    ResponseBuilder status200 [(hContentType, BS.pack "text/html"),
                               (hContentLength, BS.pack bodyLen),
                               (hConnection, BS.pack "keep-alive")]
                    $ fromLazyByteString body
    where body = root
          bodyLen = show. LB.length $ body

root = renderHtml rooth

rooth :: H.Html
rooth = H.docTypeHtml $ do
    H.body $ do
        H.h1 "Hello"

main:: IO ()
main = run 8080 application
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130709/a0b9b698/attachment-0001.htm>

------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 61, Issue 11
*****************************************

Reply via email to