401777 - InputStreamResponseListener CJK byte (>=128) cause EOF.

Fixed by adding & 0xFF when returning bytes as integers.
This commit is contained in:
Simone Bordet 2013-02-26 15:36:48 +01:00
parent 42475b1564
commit a252841561
2 changed files with 43 additions and 1 deletions

View File

@ -220,7 +220,7 @@ public class InputStreamResponseListener extends Response.Listener.Empty
else if (bytes != null)
{
if (index < bytes.length)
return bytes[index++];
return bytes[index++] & 0xFF;
length.addAndGet(-index);
bytes = null;
index = 0;

View File

@ -58,6 +58,8 @@ import org.junit.Assert;
import org.junit.Test;
import static java.nio.file.StandardOpenOption.CREATE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class HttpClientStreamTest extends AbstractHttpClientServerTest
@ -150,6 +152,46 @@ public class HttpClientStreamTest extends AbstractHttpClientServerTest
Assert.assertSame(response, result.getResponse());
}
@Test
public void testDownloadOfUTF8Content() throws Exception
{
final byte[] data = new byte[]{(byte)0xC3, (byte)0xA8}; // UTF-8 representation of &egrave;
start(new AbstractHandler()
{
@Override
public void handle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
baseRequest.setHandled(true);
response.getOutputStream().write(data);
}
});
InputStreamResponseListener listener = new InputStreamResponseListener();
client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.send(listener);
Response response = listener.get(5, TimeUnit.SECONDS);
Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus());
InputStream input = listener.getInputStream();
Assert.assertNotNull(input);
for (byte b : data)
{
int read = input.read();
assertTrue(read >= 0);
assertEquals(b & 0xFF, read);
}
assertEquals(-1, input.read());
Result result = listener.await(5, TimeUnit.SECONDS);
Assert.assertNotNull(result);
Assert.assertFalse(result.isFailed());
Assert.assertSame(response, result.getResponse());
}
@Test
public void testDownloadWithFailure() throws Exception
{