diff --git a/LICENSE b/LICENSE
new file mode 100644
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,31 @@
+Copyright (c) 2012-2013 Stevens Institute of Technology
+
+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.
+
+    * Neither the name of Stevens Institute of Technology nor the
+      names of the authors other contributors may be used to endorse
+      or promote products derived from this software without specific
+      prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"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
+OWNER OR CONTRIBUTORS 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/Network/HTTP/Proxy/Server.hs b/Network/HTTP/Proxy/Server.hs
new file mode 100644
--- /dev/null
+++ b/Network/HTTP/Proxy/Server.hs
@@ -0,0 +1,120 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+-- | A library for programming custom proxy servers.
+module Network.HTTP.Proxy.Server (proxyMain 
+                                 ,Settings (..)
+                                 ,Cache (..)
+                                 ,Default(..)) where
+
+import Network.HTTP hiding (port)
+import Network.HTTP.Server hiding (Response, Request)
+import Network.HTTP.Server.Logger
+import Data.Default.Class
+import Network.HostName
+
+-- | Proxy entry-point. Spawns a new proxy server.
+proxyMain :: forall s. HStream s => Settings s -> IO ()
+proxyMain settings = 
+  do hname <- case hostname settings of
+       Nothing -> getHostName
+       Just hostn -> return hostn
+     let config = defaultConfig {srvPort = fromInteger $ portnum settings
+                                ,srvHost = hname
+                                ,srvLog  = mylogger}
+     putStrLn "Proxy server started on port 3128\n"
+     serverWith config (proxyHandler settings)
+     
+mylogger = stdLogger
+
+proxyHandler :: HStream s => Settings s -> Handler s
+proxyHandler settings _ _ request = 
+  -- check that the request is authorized
+  isAuthorized settings request >>= 
+  \authorized -> if authorized then processRequest settings request
+                 else errorProxyUnauthorized
+                      
+-- |Processes the request; this is the main proxy procedure                     
+processRequest :: HStream s => Settings s -> Request s -> IO (Response s)
+processRequest settings request = do
+  -- modify the request
+  modRequest <- requestModifier settings request
+  -- check the cache
+  mCachedResponse <- queryCache (cache settings) modRequest
+  case mCachedResponse of
+    -- found in cache: return
+    Just response -> return response
+    -- not found: fetch it from a remote server, invoke the
+    -- 'responseModifier' hook, record in cache and return
+    Nothing       -> do 
+      response <- fetch request
+      modResponse <- responseModifier settings request response
+      recordInCache (cache settings) request modResponse 
+      return modResponse
+      
+fetch :: HStream s => Request s -> IO (Response s)
+fetch request = do
+  result <- simpleHTTP request
+  case result of 
+    Left err  -> do putStrLn ("Connection error: " ++ show err)
+                    errorInternalServerError
+    Right rsp -> return rsp
+    
+-- | Proxy server settings                
+data Settings s = 
+  Settings {requestModifier  :: Request s -> IO (Request s)
+            -- ^ A function for modifying requests. Will be called for
+            -- each request received; the modified request will be
+            -- forwarded to the target server. Defaults to an identity
+            -- function.
+           ,responseModifier :: Request s -> Response s -> IO (Response s)
+            -- ^ A function for modifying responses. Will be called
+            -- for each response received; the modified response will
+            -- be forwarded to the client. Defaults to an identity
+            -- function.
+           ,cache            :: Cache s
+            -- ^ The cache. Use 'def' for no cache.
+           ,isAuthorized     :: Request s -> IO Bool
+            -- ^ Authorization function. Allows denying certain
+            -- requests. Defaults to allowing all requests
+           ,logger           :: String -> IO ()
+            -- ^ A logging function. The default is no logging.
+           ,portnum          :: Integer
+            -- ^ Proxy server port number; default is 3128
+           ,hostname         :: Maybe String
+            -- ^ The server host name. Defaults to the result of
+            -- 'getHostName'
+           }
+
+instance Default (Settings s) where
+  def = Settings {requestModifier  = return
+                 ,responseModifier = \_ -> return
+                 ,cache            = def
+                 ,isAuthorized     = return . const True
+                 ,logger           = \_ -> return ()
+                 ,portnum          = 3128
+                 ,hostname         = Nothing}
+
+-- | The cache.
+data Cache s = Cache {queryCache :: Request s -> IO (Maybe (Response s))
+                      -- ^ Retreive the response to a request from the
+                      -- cache.
+                     ,recordInCache :: Request s -> Response s -> IO ()
+                      -- ^ Record the response to a request in the
+                      -- cache.
+                     }
+
+instance Default (Cache s) where
+  def = Cache {queryCache = return . const Nothing
+              ,recordInCache = \_ -> return . const ()}
+        
+-- |A generic 500 response
+errorInternalServerError :: HStream s => IO (Response s)
+errorInternalServerError = return $ err_response InternalServerError
+
+-- |A generic 407 response. TODO: RFC 2068 requres to send
+-- Proxy-Authenticate header with this response code
+errorProxyUnauthorized :: HStream s => IO (Response s)
+errorProxyUnauthorized = return $ err_response ProxyAuthenticationRequired
+
+-- |A generic 400 response
+errorBadRequest :: HStream s => IO (Response s)
+errorBadRequest = return $ err_response BadRequest
diff --git a/Setup.hs b/Setup.hs
new file mode 100644
--- /dev/null
+++ b/Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
diff --git a/haxy.cabal b/haxy.cabal
new file mode 100644
--- /dev/null
+++ b/haxy.cabal
@@ -0,0 +1,43 @@
+Name:                haxy
+Version:             0.9
+Synopsis:            A simple HTTP proxy server library
+Description:         A library for writing HTTP proxy servers with the focus on simplicity, flexibility and modularity. Allows arbitrary transformations on requests and responses and custom caching methods. It's up to the user to make sure that the message transformations are consistent with the HTTP specification. The executable program is a simple non-caching identity proxy and is used for testing the library.
+License:             BSD3
+License-file:        LICENSE
+Author:              Andrey Chudnov
+Maintainer:          Andrey Chudnov <oss@chudnov.com>
+Copyright:           (c) 2012-2013 Stevens Institute of Technology
+Category:            Web
+Build-type:          Simple
+Stability:           Stable
+Cabal-version:       >=1.10
+
+source-repository head
+   type: git
+   location: git://github.com/achudnov/haxy.git
+
+source-repository this
+   type: git
+   location: git://github.com/achudnov/haxy.git
+   tag: 0.9
+
+Library
+  Exposed-modules: Network.HTTP.Proxy.Server
+  Build-depends: http-server  >= 1.0.3 && < 1.1
+               , HTTP         >= 4000.2.0 && < 5000
+               , base         >= 4.3.1.0 && < 5
+               , url          >= 2.1.2 && < 2.2
+               , bytestring   >= 0.9.1.10 && < 0.10
+               , data-default-class >= 0.0.1 && < 0.1
+               , hostname     >= 1.0 && < 2
+  Default-Language: Haskell2010
+
+Executable simple-proxy
+   Main-Is: test/IdProxy.hs
+   Build-Depends: base         >= 4.3.1.0 && < 5
+                , bytestring   >= 0.9.1.10 && < 0.10
+                , data-default-class >= 0.0.1 && < 0.1
+                , hostname     >= 1.0 && < 2
+                , http-server  >= 1.0.3 && < 1.1
+                , HTTP         >= 4000.2.0 && < 5000
+   Default-Language: Haskell2010
diff --git a/test/IdProxy.hs b/test/IdProxy.hs
new file mode 100644
--- /dev/null
+++ b/test/IdProxy.hs
@@ -0,0 +1,7 @@
+module Main where
+
+import Network.HTTP.Proxy.Server
+import Data.Default.Class
+import Data.ByteString
+
+main = proxyMain (def :: Settings ByteString) {hostname = Just "localhost"}
