I'm trying to write HTML to a page when a certain path is hit:
import Control.Monad
import Data.Char
import System.IO
import Network
import Data.Time.LocalTime
data RequestType = GET | POST deriving (Show)
data Request = Request { rtype :: RequestType, path :: String, options :: [(String,String)] }
data Response = Response { version :: String, statuscode :: Int }
instance Show Response where
show r = version(r) ++ " " ++ show(statuscode(r)) ++ " " ++ (case statuscode(r) of
100 -> "Continue"
200 -> "OK"
404 -> "Not Found") ++ "\r\n\r\n"
-- respond function
respond :: Request -> Handle -> IO ()
respond request handle = do
putStrLn $ show request
let response = Response {version = "HTTP/1.1", statuscode = 200}
hPutStr handle $ show(response)
hPutStr handle $ "Haskell says " ++ (getMessage request)
where getMessage r
| (path r) == "/hello" = "<b>hello there!</b>" <-- HERE
| otherwise = (path r)
I can run this code without errors, but when I hit http://{hostname}/hello I get the string <b>hello there!</b>
meaning the html is being rendered as a string.
How do I render it as html?
NOTE
I want to do this using vanilla Haskell, meaning no 3rd party libraries.