diff options
| author | Andrew Guschin <guschin.drew@gmail.com> | 2023-03-05 13:45:37 +0400 |
|---|---|---|
| committer | Andrew Guschin <guschin.drew@gmail.com> | 2023-03-05 13:47:41 +0400 |
| commit | a0e8e5a91d15ed8c79f4a1b5914d3a6242c0cbd3 (patch) | |
| tree | 76f76788523a16c0db8cb8f3a90b23912acd37d4 /app/Web/Response.hs | |
| parent | dd73de2e563c332c5a90bb21c5c7e6cbebc0ab86 (diff) | |
Migrated project to cabal
Diffstat (limited to 'app/Web/Response.hs')
| -rw-r--r-- | app/Web/Response.hs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/app/Web/Response.hs b/app/Web/Response.hs new file mode 100644 index 0000000..3c393ad --- /dev/null +++ b/app/Web/Response.hs @@ -0,0 +1,30 @@ +module Web.Response where + +import qualified Data.Text as T +import Data.Text (Text) + +import Web.Utils + +data Response + = HtmlResponse Int Text -- Код возврата, содержимое HTML + | TextResponse Int Text Text -- Код возврата, Content-Type, содержимое HTML + deriving Show + +notFoundResponse = HtmlResponse 404 (T.pack "<strong>404 Not Found</strong>") + +getStatusCode (HtmlResponse code _) = code +getStatusCode (TextResponse code _ _) = code + +getContentType (HtmlResponse _ _) = (T.pack "text/html") +getContentType (TextResponse _ contentType _) = contentType + +getContent (HtmlResponse _ content) = content +getContent (TextResponse _ _ content) = content + +formResponse :: Response -> Text +formResponse (HtmlResponse code html) = + T.strip $ T.unlines + $ map T.pack [ "HTTP/1.1 " ++ getStatus code + , "Content-Type: text/html; charset=utf-8" + , "Connection: close" + , "" ] ++ [html] |