401777 - InputStreamResponseListener CJK byte (>=128) cause EOF.
Fixed by adding & 0xFF when returning bytes as integers.
This commit is contained in:
parent
42475b1564
commit
a252841561
|
@ -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;
|
||||
|
|
|
@ -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 è
|
||||
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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue