https://issues.apache.org/bugzilla/show_bug.cgi?id=50753

           Summary: Asynchronous responses do not contain set response
                    headers
           Product: Tomcat 7
           Version: 7.0.6
          Platform: PC
        OS/Version: Mac OS X 10.5
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
        AssignedTo: dev@tomcat.apache.org
        ReportedBy: mircea.t...@icesoft.com


Using a servlet with asynchronous support enabled and the response headers set
just before AsyncContext.complete() method is called fails to send the headers
over the wire. More precisely if the headers are set on the HttpServletRequest
on a different thread than the request thread the headers are not sent. 

A simple test was devised to showcase the issue.

Setting the headers on the request thread before or after the AsyncContext is
acquired *succeeds* in sending the headers over the wire: 

    protected void doGet(HttpServletRequest request, final HttpServletResponse
r) throws ServletException, IOException { 
       final AsyncContext ctx = request.startAsync(); 
        r.setHeader("A", "xyz"); 
        r.setContentType("text/plain"); 
        r.setContentLength("------".getBytes().length); 
        r.getWriter().print("------"); 
        ctx.start(new Runnable() { 
            public void run() { 
                try { 
                    Thread.sleep(5000); 
                    ctx.complete(); 
                } catch (Exception e) { 
                    e.printStackTrace();
                } 
            } 
        }); 
    } 

Setting the headers just before the response is sent *does not succeed* in
actually sending the headers over the wire: 

    protected void doGet(HttpServletRequest request, final HttpServletResponse
r) throws ServletException, IOException { 
       final AsyncContext ctx = request.startAsync(); 
        ctx.start(new Runnable() { 
            public void run() { 
                try { 
                    Thread.sleep(5000); 
                    r.setHeader("A", "xyz"); 
                    r.setContentType("text/plain"); 
                    r.setContentLength("------".getBytes().length); 
                    r.getWriter().print("------"); 
                    ctx.complete(); 
                } catch (Exception e) { 
                    e.printStackTrace();
                } 
            } 
        }); 
    }

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to