diff --git a/Hack/Middleware/Jsonp.hs b/Hack/Middleware/Jsonp.hs
new file mode 100644
--- /dev/null
+++ b/Hack/Middleware/Jsonp.hs
@@ -0,0 +1,63 @@
+---------------------------------------------------------
+-- |
+-- Module        : Hack.Middleware.Jsonp
+-- Copyright     : Michael Snoyman
+-- License       : BSD3
+--
+-- Maintainer    : Michael Snoyman <michael@snoyman.com>
+-- Stability     : Unstable
+-- Portability   : portable
+--
+-- Automatic wrapping of JSON responses to convert into JSONP.
+--
+---------------------------------------------------------
+module Hack.Middleware.Jsonp (jsonp) where
+
+import Hack
+import Web.Encodings (decodeUrlPairs)
+import Data.ByteString.Class (toLazyByteString)
+import qualified Data.ByteString.Lazy as BS
+import Data.Maybe (fromMaybe)
+import Data.List (isInfixOf)
+
+-- | Wrap json responses in a jsonp callback.
+--
+-- Basically, if the user requested a \"text\/javascript\" and supplied a
+-- \"callback\" GET parameter, ask the application for an
+-- \"application/json\" response, then convern that into a JSONP response,
+-- having a content type of \"text\/javascript\" and calling the specified
+-- callback function.
+jsonp :: Middleware
+jsonp app env = do
+    let accept = fromMaybe "" $ lookup "HTTP_ACCEPT" $ http env
+    let gets = decodeUrlPairs $ queryString env
+    let callback :: Maybe String
+        callback =
+            if "text/javascript" `isInfixOf` accept
+                then lookup "callback" gets
+                else Nothing
+    let env' =
+            case callback of
+                Nothing -> env
+                Just _ -> env
+                        { http = changeVal "HTTP_ACCEPT"
+                                           "application/json"
+                                           $ http env
+                        }
+    res <- app env'
+    case callback of
+            Nothing -> return res
+            Just c -> return $ res
+                    { headers = changeVal "Content-type"
+                                          "text/javascript"
+                                          $ headers res
+                    , body = BS.concat
+                                [ toLazyByteString c
+                                , toLazyByteString "("
+                                , body res
+                                , toLazyByteString ")"
+                                ]
+                    }
+
+changeVal :: String -> String -> [(String, String)] -> [(String, String)]
+changeVal key val old = (key, val) : filter (\(k, _) -> k /= key) old
diff --git a/LICENSE b/LICENSE
new file mode 100644
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,25 @@
+The following license covers this documentation, and the source code, except
+where otherwise indicated.
+
+Copyright 2008, Michael Snoyman. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+  list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+  this list of conditions and the following disclaimer in the documentation
+  and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR
+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/Setup.lhs b/Setup.lhs
new file mode 100644
--- /dev/null
+++ b/Setup.lhs
@@ -0,0 +1,7 @@
+#!/usr/bin/env runhaskell
+
+> module Main where
+> import Distribution.Simple
+
+> main :: IO ()
+> main = defaultMain
diff --git a/hack-middleware-jsonp.cabal b/hack-middleware-jsonp.cabal
new file mode 100644
--- /dev/null
+++ b/hack-middleware-jsonp.cabal
@@ -0,0 +1,18 @@
+name:            hack-middleware-jsonp
+version:         0.0.0
+license:         BSD3
+license-file:    LICENSE
+author:          Michael Snoyman <michael@snoyman.com>
+maintainer:      Michael Snoyman <michael@snoyman.com>
+synopsis:        Automatic wrapping of JSON responses to convert into JSONP.
+category:        Web
+stability:       unstable
+cabal-version:   >= 1.2
+build-type:      Simple
+homepage:        http://github.com/snoyberg/hack-middleware-jsonp/tree/master
+
+library
+    build-depends:   base >= 3, bytestring >= 0.9.1.4, bytestring-class,
+                     web-encodings, hack >= 2009.5.19
+    exposed-modules: Hack.Middleware.Jsonp
+    ghc-options:     -Wall
