]> gitweb @ CieloNegro.org - Lucu.git/commitdiff
bugfix
authorPHO <pho@cielonegro.org>
Mon, 31 Oct 2011 16:28:48 +0000 (01:28 +0900)
committerPHO <pho@cielonegro.org>
Mon, 31 Oct 2011 16:28:48 +0000 (01:28 +0900)
Ditz-issue: 8959dadc07db1bd363283dee401073f6e48dc7fa

Network/HTTP/Lucu/MultipartForm.hs
examples/SSL.hs

index 53174fa94d0a2f0ac448e4a53182800e5da64c43..edba0d50f1e33e589feeb10b57ec71dbe4ebb3da 100644 (file)
@@ -5,6 +5,7 @@
   , RecordWildCards
   , ScopedTypeVariables
   , UnicodeSyntax
+  , ViewPatterns
   #-}
 -- |Parse \"multipart/form-data\" based on RFC 2388:
 -- <http://www.faqs.org/rfcs/rfc2388.html>
@@ -23,7 +24,8 @@ import Data.Ascii (Ascii, CIAscii)
 import qualified Data.Ascii as A
 import Data.Attoparsec
 import qualified Data.Attoparsec.Lazy as LP
-import qualified Data.ByteString.Lazy.Char8 as LS
+import qualified Data.ByteString as BS
+import qualified Data.ByteString.Lazy as LS
 import Data.ByteString.Lazy.Search
 import Data.Foldable
 import Data.List
@@ -207,11 +209,16 @@ getBody ∷ MonadError String m
         → LS.ByteString
         → m (LS.ByteString, LS.ByteString)
 {-# INLINEABLE getBody #-}
-getBody boundary src
-    = case breakFindAfter (A.toByteString boundary) src of
-        ((before, after), True)
-            → return (before, after)
-        _   → throwError "missing boundary"
+getBody (("\r\n--" ⊕) ∘ A.toByteString → boundary) src
+    = case breakOn boundary src of
+        (before, after)
+            | LS.null after
+                → throwError "missing boundary"
+            | otherwise
+                → let len    = fromIntegral $ BS.length boundary
+                      after' = LS.drop len after
+                  in
+                    return (before, after')
 
 partToFormPair ∷ MonadError String m ⇒ Part → m (Ascii, FormData)
 {-# INLINEABLE partToFormPair #-}
index 48b23813fbee4f2a746b2940fadf9252cba06965..6df2ab714e37c5ce4c265c8d10c1f176b5632894 100644 (file)
@@ -41,12 +41,12 @@ helloWorld
     = emptyResource {
         resGet
           = Just $ do setContentType $ parseMIMEType "text/plain"
-                      outputChunk "getRemoteCertificate = "
+                      putChunk "getRemoteCertificate = "
                       cert ← do cert ← getRemoteCertificate
                                 case cert of
                                   Just c  → liftIO $ Lazy.pack <$> printX509 c
                                   Nothing → return "Nothing"
-                      outputChunk cert
+                      putChunks cert
       }
 
 genCert ∷ KeyPair k ⇒ k → IO X509