Changeset 1088

Show
Ignore:
Timestamp:
06/12/08 01:00:39 (3 months ago)
Author:
kris
Message:

added a cookie servlet, to set a test cookie

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/example/net/servlets.d

    r1079 r1088  
    3333        tango.util.log.Config; 
    3434 
     35import  tango.net.http.HttpCookies; 
     36 
    3537        // for testing the http server 
    3638import  mango.net.http.server.HttpServer; 
     
    8587                if (! response.copyFile (request.context, request.pathInfo)) 
    8688                      logger.warn ("cannot locate file: " ~ request.uri.getPath); 
     89        } 
     90} 
     91 
     92 
     93/******************************************************************************* 
     94 
     95        Servlet to return a file. 
     96 
     97*******************************************************************************/ 
     98 
     99class CookieServlet : MethodServlet 
     100{ 
     101        /*********************************************************************** 
     102 
     103                support GET requests only! All other method requests will 
     104                return an error to the user-agent 
     105 
     106        ***********************************************************************/ 
     107 
     108        void doGet (IServletRequest request, IServletResponse response) 
     109        { 
     110                scope cook = new Cookie("echo_cookie", "'some/value'"); 
     111                //cook.setDomain("apple.com"); 
     112                cook.setPath("/"); 
     113                response.cookies.add(cook); 
     114 
     115                response.buffer.append ("you have a cookie"); 
     116                response.setStatus(HttpResponses.OK); 
    87117        } 
    88118} 
     
    215245        auto example = sp.addContext (new ServletContext ("/example")); 
    216246 
     247        // map cookie requests to our cookie servlet 
     248        sp.addMapping ("/cookie", sp.addServlet (new CookieServlet, example)); 
     249 
    217250        // map echo requests to our echo servlet 
    218251        sp.addMapping ("/echo", sp.addServlet (new Echo, example));