@@ -72,41 +72,45 @@ public State read(ByteBuffer buffer) throws IOException {
72
72
chunk = new byte [buffer .remaining () - 10 ];
73
73
74
74
int read = -1 ;
75
+ boolean write = false ;
75
76
try {
76
77
read = inputStream .read (chunk );
77
78
} catch (IOException ex ) {
78
79
LOGGER .warn ("Unable to read" , ex );
79
80
}
80
81
81
82
if (patchNetty3ChunkingIssue ) {
82
- if (read == -1 ) {
83
- // Since we are chunked, we must output extra bytes before considering the input stream closed.
84
- // chunking requires to end the chunking:
85
- // - A Terminating chunk of "0\r\n".getBytes(),
86
- // - Then a separate packet of "\r\n".getBytes()
87
- if (!eof ) {
88
- endDataCount ++;
89
-
90
- if (endDataCount == 1 )
91
- buffer .put (ZERO );
92
- else if (endDataCount == 2 )
93
- eof = true ;
94
-
95
- buffer .put (END_PADDING );
96
- }
97
- } else {
83
+ if (read >= 0 ) {
98
84
// Netty 3.2.3 doesn't support chunking encoding properly, so we chunk encoding ourself.
99
85
buffer .put (Integer .toHexString (read ).getBytes ());
100
86
// Chunking is separated by "<bytesreads>\r\n"
101
87
buffer .put (END_PADDING );
102
88
buffer .put (chunk , 0 , read );
103
89
// Was missing the final chunk \r\n.
104
90
buffer .put (END_PADDING );
91
+ write = true ;
92
+
93
+ } else if (!eof ) {
94
+ // read == -1)
95
+ // Since we are chunked, we must output extra bytes before considering the input stream closed.
96
+ // chunking requires to end the chunking:
97
+ // - A Terminating chunk of "0\r\n".getBytes(),
98
+ // - Then a separate packet of "\r\n".getBytes()
99
+ endDataCount ++;
100
+
101
+ if (endDataCount == 1 )
102
+ buffer .put (ZERO );
103
+ else if (endDataCount == 2 )
104
+ eof = true ;
105
+
106
+ buffer .put (END_PADDING );
107
+ write = true ;
105
108
}
106
109
} else if (read > 0 ) {
107
110
buffer .put (chunk , 0 , read );
111
+ write = true ;
108
112
}
109
- return read < 0 ? State .Stop : State .Continue ;
113
+ return write ? State .Continue : State .Stop ;
110
114
}
111
115
112
116
public void close () throws IOException {
0 commit comments