on master help sign in
Merge remote-tracking branch 'main/embedded' into embedded
9defb58Greg Weber
Network/Wai/Application/Static.hs+5−2
@@ -315,7 +315,7 @@ checkPieces fileLookup indices pieces req maxAge
315
315
316 cacheControl = case ccInt of
316 cacheControl = case ccInt of
317 Nothing -> []
317 Nothing -> []
318− Just i -> [("Cache-Control", S8.append "max-age" $ S8.pack $ show i)]
318+ Just i -> [("Cache-Control", S8.append "max-age=" $ S8.pack $ show i)]
319 where
319 where
320 ccInt =
320 ccInt =
321 case maxAge of
321 case maxAge of
@@ -344,7 +344,10 @@ data File = File
344 }
344 }
345
345
346parseDate :: ByteString -> Maybe EpochTime
346parseDate :: ByteString -> Maybe EpochTime
347−parseDate = error "parseDate"
347+parseDate =
348+ fmap (fromIntegral . fromEnum . utcTimeToPOSIXSeconds) . parseTime defaultTimeLocale format . S8.unpack
349+ where
350+ format = "%a, %d %b %Y %X %Z"
348
351
349data StaticSettings = StaticSettings
352data StaticSettings = StaticSettings
350 { ssFolder :: Pieces -> IO FileLookup
353 { ssFolder :: Pieces -> IO FileLookup
tests/runtests.hs+5−5
@@ -57,7 +57,7 @@ main = hspecX $ do
57
57
58
58
59 let cacheLookup = MaxAgeForever -- (\fp h -> fp == "tests/runtests.hs" && h == "cached")
59 let cacheLookup = MaxAgeForever -- (\fp h -> fp == "tests/runtests.hs" && h == "cached")
60− let statApp = flip runSession $ staticApp defaultWebAppSettings -- cacheLookup) {ssFolder = "tests"}
60+ let statApp = flip runSession $ staticApp defaultFileServerSettings {ssFolder = fileSystemLookup "tests"}
61 describe "staticApp" $ do
61 describe "staticApp" $ do
62 it "403 for unsafe paths" $ statApp $
62 it "403 for unsafe paths" $ statApp $
63 flip mapM_ ["..", "."] $ \path ->
63 flip mapM_ ["..", "."] $ \path ->
@@ -87,9 +87,9 @@ main = hspecX $ do
87 assertStatus 301 req
87 assertStatus 301 req
88 assertHeader "Location" "../../a/b/c" req
88 assertHeader "Location" "../../a/b/c" req
89
89
90− let absoluteApp = flip runSession $ staticApp $ defaultWebAppSettings -- cacheLookup) {
90+ let absoluteApp = flip runSession $ staticApp $ defaultWebAppSettings {
91− -- ssFolder = "tests", ssMkRedirect = \_ u -> S8.append "http://www.example.com" u
91+ ssFolder = fileSystemLookup "tests", ssMkRedirect = \_ u -> S8.append "http://www.example.com" u
92− -- }
92+ }
93 it "301 redirect when multiple slashes" $ absoluteApp $
93 it "301 redirect when multiple slashes" $ absoluteApp $
94 flip mapM_ ["/a//b/c", "a//b/c"] $ \path -> do
94 flip mapM_ ["/a//b/c", "a//b/c"] $ \path -> do
95 req <- request (setRawPathInfo defRequest path)
95 req <- request (setRawPathInfo defRequest path)
@@ -124,7 +124,7 @@ main = hspecX $ do
124 assertStatus 304 req
124 assertStatus 304 req
125 assertNoHeader "Cache-Control" req
125 assertNoHeader "Cache-Control" req
126
126
127− let pubApp = flip runSession $ staticApp defaultWebAppSettings -- $ ETag (\_ -> return $ Just "hash")) {ssFolder = "tests"}
127+ let pubApp = flip runSession $ staticApp defaultWebAppSettings {ssFolder = fileSystemLookup "tests"}
128 describe "staticApp when requesting a public asset - etags" $ do
128 describe "staticApp when requesting a public asset - etags" $ do
129 it "200 when no etag parameters" $ pubApp $ do
129 it "200 when no etag parameters" $ pubApp $ do
130 req <- request (setRawPathInfo defRequest "runtests.hs")
130 req <- request (setRawPathInfo defRequest "runtests.hs")