Bug 64255

Summary: tomcat-embed:chunked responses with header 'connetion:close' are damaged
Product: Tomcat 9 Reporter: taojiaen <taojiaen>
Component: ServletAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED INVALID    
Severity: normal    
Priority: P2    
Version: 9.0.x   
Target Milestone: -----   
Hardware: All   
OS: All   

Description taojiaen 2020-03-22 16:06:35 UTC
version:9.0.31


code segment is here

        Tomcat.addServlet(ctx, "hello", new HttpServlet() {

            private static final long serialVersionUID = -8721082143781719844L;

            @Override
            protected void doGet(HttpServletRequest req, HttpServletResponse resp)
                throws IOException {
                resp.setStatus(200);
                resp.setHeader("Transfer-Encoding", "chunked");
                resp.setHeader("Connection", "close");
                resp.getOutputStream().write('{');
                resp.getOutputStream().flush();
            }
        });

and use curl there will be

curl 'http://localhost:8089/hello'
curl: (56) Illegal or missing hexadecimal sequence in chunked-encoding


the compele code is here

https://github.com/taojiaenx/tomcat-chunk-error.git
Comment 1 Mark Thomas 2020-03-22 19:30:26 UTC
If the application takes responsibility for setting the chunked encoding header it also has to take responsibility sending for a correctly encoded body.

Generally, it is much simpler to let the container handle chunked encoding.
Comment 2 taojiaen 2020-03-24 09:26:32 UTC
(In reply to Mark Thomas from comment #1)
> If the application takes responsibility for setting the chunked encoding
> header it also has to take responsibility sending for a correctly encoded
> body.
> 
> Generally, it is much simpler to let the container handle chunked encoding.

Even If I change the body into a simple character or other string, it also damaged.How can I solve this problem ?

I just send a simple character is it not a correctly body?and It worked well when I use jetty or undertow, when I remove the header "connetion:close", it also worked well.

Have I do some illegal operation?
Comment 3 taojiaen 2020-03-24 09:36:37 UTC
(In reply to Mark Thomas from comment #1)
> If the application takes responsibility for setting the chunked encoding
> header it also has to take responsibility sending for a correctly encoded
> body.
> 
> Generally, it is much simpler to let the container handle chunked encoding.

thx for reply a really want to know what happend, I have worked it on for weeks and have no idea about it.
the related bug is reported on github
https://github.com/spring-cloud/spring-cloud-gateway/issues/1600#event-3129620407
https://github.com/spring-projects/spring-framework/issues/24699#issuecomment-600742824
Comment 4 Mark Thomas 2020-03-24 09:38:12 UTC
Bugzilla is not a support forum.

If you want to ask questions, use the Tomcat users mailing list.