/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
*
* @bug 4333920
* @bug 4394548
* @summary Check that chunked encoding response doesn't cause
* getInputStream to block until last chunk arrives.
* Also regression against NPE in ChunkedInputStream.
*/
/*
* Our "http" server to return a chunked response
*/
public void run() {
try {
new BufferedOutputStream(
s.getOutputStream() ));
/* send the header */
/* delay the server before first chunk */
/*
* Our response will be of random length
* but > 32k
*/
int len;
do {
/*
* Our chunk size will be 2-32k
*/
int chunkSize;
do {
/*
* Generate random content and check sum it
*/
int cs = 0;
for (int i=0; i<len; i++) {
}
/*
* Stream the chunks to the client
*/
int pos = 0;
while (remaining > 0) {
}
/* send EOF chunk */
/*
* Send trailer with checksum
*/
s.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/* start the server */
/* establish http connection to server */
"/foo";
/*
* Server should only send headers if TE:trailers
* specified - see updated HTTP 1.1 spec.
*/
/* Time how long the getInputStream takes */
/*
* If getInputStream takes >2 seconds it probably means
* that the implementation is waiting for the chunks to
* arrive.
*/
throw new Exception("getInputStream didn't return immediately");
}
/*
* Read the stream and checksum it as it arrives
*/
int nread;
int cs = 0;
byte b[] = new byte[1024];
do {
if (nread > 0) {
for (int i=0; i<nread; i++) {
}
}
} while (nread > 0);
/*
* Verify that the checksums match
*/
throw new Exception("Checksum trailer missing from response");
}
throw new Exception("Trailer checksum doesn't equal calculated checksum");
}
http.disconnect();
}
new ChunkedEncoding();
}
}