anchor.diff:          {"your-attack", list_to_binary(Attack1)},
           {"their-attack", list_to_binary(Attack2)}
       ]})),
  -    Req:ok({"application/javascript", JSON}).
  +    mochiweb_request:ok({"application/javascript", JSON}, Req).
   
   redirect(Req, Path) ->
  -    Location = "http://" ++ Req:get_header_value("host") ++ "/" ++ Path,
  -    Req:respond({302, [{"Location", Location }], "Redirecting to " ++ Path ++ "\n"}).
  +    Host = mochiweb_request:get_header_value("host", Req),
  +    Location = "http://" ++ Host ++ "/" ++ Path,
  +    mochiweb_request:respond({302, [{"Location", Location }], "Redirecting to " ++ Path ++ "\n"}, Req).
  
positive.code: %% Comet callback: join a game and wait for the other player
  %% POST /<game-uuid>/join (data: name=AgentX)
  handle('POST', [Uuid, "join"], Req) ->
      Data = mochiweb_util:parse_qs(Req:recv_body()),
      Name = proplists:get_value("name", Data),
      {Game, Opponent} = gameserver:join(Name, Uuid),
      JSON = iolist_to_binary(mochijson2:encode({struct, [
          {"game", list_to_binary(Game)},
          {"opponent", list_to_binary(Opponent)}
      ]})),
      Req:ok({"application/javascript", JSON});
  
  %% Comet callback: play a hand and wait for the other players hand
  %% POST /<game-uuid>/attack (data: attack=rock)
  
negative.code: handle('GET', [UUID], Req) ->
      % make sure the URL ends with a slash ("/")
      % if not, redirect to the same URL with / appended
      case string:right(mochiweb_request:get(path, Req), 1) of
          "/" ->
              mochiweb_request:serve_file("game.html", "./static", Req);
          _ ->
              redirect(Req, UUID ++ "/")
      end;
  