+mkModule ∷ ModuleName → Name → [ImportDecl] → [Decl]
+mkModule modName symName imports decls
+ = let modPragma = [ LanguagePragma (⊥) [ name (show OverloadedStrings)
+ ]
+ ]
+ exports = [ EVar (UnQual symName)
+ ]
+ in
+ Module (⊥) modName modPragma Nothing (Just exports) imports decls
+
+mkImports ∷ Bool → [ImportDecl]
+mkImports useGZip
+ = [ ImportDecl (⊥) (ModuleName "Data.ByteString.Base64")
+ True False (Just (ModuleName "B64")) Nothing
+ , ImportDecl (⊥) (ModuleName "Data.ByteString.Lazy")
+ True False (Just (ModuleName "Lazy")) Nothing
+ , ImportDecl (⊥) (ModuleName "Data.Time")
+ False False Nothing Nothing
+ , ImportDecl (⊥) (ModuleName "Network.HTTP.Lucu")
+ False False Nothing Nothing
+ ]
+ ⧺
+ if useGZip then
+ [ ImportDecl (⊥) (ModuleName "Codec.Compression.GZip")
+ False False Nothing Nothing
+ ]
+ else
+ []
+
+resHead ∷ Exp
+resHead
+ = infixApp (var $ name "Just")
+ (op $ name "$" )
+ (doE [ foundEntityStmt
+ , setContentTypeStmt
+ ])
+
+resGetRaw ∷ Exp
+resGetRaw
+ = infixApp (var $ name "Just")
+ (op $ name "$" )
+ (doE [ foundEntityStmt
+ , setContentTypeStmt
+ , outputStmt (var $ name "rawData")
+ ])
+
+setContentEncodingGZipStmt ∷ Stmt
+setContentEncodingGZipStmt
+ = qualStmt $
+ metaFunction "setContentEncoding" $
+ [ listE [ strE "gzip" ] ]
+
+foundEntityStmt ∷ Stmt
+foundEntityStmt
+ = qualStmt $
+ metaFunction "foundEntity" $
+ [ var $ name "entityTag"
+ , var $ name "lastModified"
+ ]
+
+setContentTypeStmt ∷ Stmt
+setContentTypeStmt
+ = qualStmt $
+ metaFunction "setContentType" $
+ [var $ name "contentType"]
+
+outputStmt ∷ Exp → Stmt
+outputStmt e
+ = qualStmt $
+ metaFunction "output" [e]
+
+entityTagDecl ∷ ETag → [Decl]
+entityTagDecl eTag
+ = [ TypeSig (⊥) [varName] (TyCon (UnQual (name "ETag")))
+ , nameBind (⊥) varName valExp
+ ]
+ where
+ varName ∷ Name
+ varName = name "entityTag"