     (= "/create-game" uri) (login/create-game-page)
     :else (login/login-page (game-state/game-names))))
 
+(defn- handler-inner [request]
+  (case (:request-method request)
+    :post (let [ message (slurp (:body request)) ]
+            (println message)
+            (try (handle-post message) (catch Throwable e (xml-to-text (handle-exception e)))))
+    :get (let [ { uri :uri query :query } request ]
+           (println uri query)
+           (handle-get uri query))))
+
 (defn handler [request]
   (reload)
   (println "------------")
-  (reply
-    (case (:request-method request)
-      :post
-        (let [ message (slurp (:body request)) ]
-          (println message)
-          (try (handle-post message) (catch Throwable e (xml-to-text (handle-exception e)))))
-      :get
-        (let [ { uri :uri query :query } request ]
-          (println uri query)
-          (handle-get uri query)))))
+  (let [ raw-reply (handler-inner request) ]
+    (if (string? raw-reply)
+      (reply raw-reply) ; format as HTTP 200 OK response
+      raw-reply ))) ; already formatted as some HTTP response
 
 (defn -main [& args]
   (game-state/load-games)

  (:require [glory-of-empires.game-state :as game-state])
  (:require [glory-of-empires.login :as login])
  (:require [glory-of-empires.html :as html]))

;----------------- web server ----------------------


    :admin-command (do (game-state/swap-games game-func) "ok")  )) ; commands modifying the whole app state

(defn handle-post [ message-str ]
  (let [ message (read-string message-str)
         { game-id :game role :role password :password message-type :message-type func :func } message
         game (game-state/game game-id)
         game-func (binding [*ns* (find-ns 'glory-of-empires.main)] (eval func))
         require-role (get (meta game-func) :require-role) ]
    (if (or (not require-role) (players/password-valid? require-role game message))
      (execute-post message-type game-id game game-func)
      (throw (Exception. (str "Password " password " for " role " not valid for role " require-role)))   )))

(defn static-page [ path ] (slurp path :encoding "UTF-8"))

(def ignore-urls #{ "/favicon.ico" "/html/jquery.min.map" } )

(defn- handle-get [ uri query ] ; returns ready response-map or string for normal HTTP 200 response
  (cond
    (contains? ignore-urls uri) ""
    (re-matches #"\/html\/.+" uri) (static-page (subs uri 1))
