Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3abe37b

Browse files
committed
minor clean up
1 parent3c25a42 commit3abe37b

File tree

2 files changed

+17
-36
lines changed

2 files changed

+17
-36
lines changed

‎client/src/test/java/org/asynchttpclient/reactivestreams/ReactiveStreamsTest.java‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,23 @@ public void testConnectionDoesNotGetClosed() throws Exception {
7575
assertEquals(response.getStatusCode(),200);
7676
byte[]responseBody =response.getResponseBodyAsBytes();
7777
responseBody =response.getResponseBodyAsBytes();
78-
assertEquals(Integer.valueOf(response.getHeader("X-" +CONTENT_LENGTH)).intValue(),LARGE_IMAGE_BYTES.length,"Serverreceived payload length invalid");
79-
assertEquals(responseBody.length,LARGE_IMAGE_BYTES.length,"Clientback payload length invalid");
80-
assertEquals(response.getHeader(CONTENT_MD5),expectedMd5,"Serverreceived payload MD5 invalid");
81-
assertEquals(TestUtils.md5(responseBody),expectedMd5,"Clientback payload MD5 invalid");
78+
assertEquals(Integer.valueOf(response.getHeader("X-" +CONTENT_LENGTH)).intValue(),LARGE_IMAGE_BYTES.length,"Serverside payload length invalid");
79+
assertEquals(responseBody.length,LARGE_IMAGE_BYTES.length,"Clientside payload length invalid");
80+
assertEquals(response.getHeader(CONTENT_MD5),expectedMd5,"Serverside payload MD5 invalid");
81+
assertEquals(TestUtils.md5(responseBody),expectedMd5,"Clientside payload MD5 invalid");
8282
assertEquals(responseBody,LARGE_IMAGE_BYTES);
8383

8484
response =requestBuilder.execute().get();
8585
assertEquals(response.getStatusCode(),200);
8686
responseBody =response.getResponseBodyAsBytes();
87-
assertEquals(Integer.valueOf(response.getHeader("X-" +CONTENT_LENGTH)).intValue(),LARGE_IMAGE_BYTES.length,"Serverreceived payload length invalid");
88-
assertEquals(responseBody.length,LARGE_IMAGE_BYTES.length,"Clientback payload length invalid");
87+
assertEquals(Integer.valueOf(response.getHeader("X-" +CONTENT_LENGTH)).intValue(),LARGE_IMAGE_BYTES.length,"Serverside payload length invalid");
88+
assertEquals(responseBody.length,LARGE_IMAGE_BYTES.length,"Clientside payload length invalid");
8989
try {
90-
assertEquals(response.getHeader(CONTENT_MD5),expectedMd5,"Serverreceived payload MD5 invalid");
91-
assertEquals(TestUtils.md5(responseBody),expectedMd5,"Clientback payload MD5 invalid");
90+
assertEquals(response.getHeader(CONTENT_MD5),expectedMd5,"Serverside payload MD5 invalid");
91+
assertEquals(TestUtils.md5(responseBody),expectedMd5,"Clientside payload MD5 invalid");
9292
assertEquals(responseBody,LARGE_IMAGE_BYTES);
9393
}catch (AssertionErrore) {
94+
e.printStackTrace();
9495
for (inti =0;i <LARGE_IMAGE_BYTES.length;i++) {
9596
assertEquals(responseBody[i],LARGE_IMAGE_BYTES[i],"Invalid response byte at position " +i);
9697
}

‎client/src/test/java/org/asynchttpclient/test/EchoHandler.java‎

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
packageorg.asynchttpclient.test;
1515

1616
importstaticio.netty.handler.codec.http.HttpHeaderNames.*;
17-
importio.netty.buffer.ByteBufUtil;
18-
importio.netty.buffer.Unpooled;
19-
importio.netty.util.internal.StringUtil;
2017

2118
importjava.io.IOException;
2219
importjava.util.Enumeration;
@@ -26,6 +23,7 @@
2623
importjavax.servlet.http.HttpServletRequest;
2724
importjavax.servlet.http.HttpServletResponse;
2825

26+
importorg.apache.commons.io.IOUtils;
2927
importorg.eclipse.jetty.server.Request;
3028
importorg.eclipse.jetty.server.handler.AbstractHandler;
3129
importorg.slf4j.Logger;
@@ -106,35 +104,17 @@ public void handle(String pathInContext, Request request, HttpServletRequest htt
106104
}
107105
}
108106

109-
StringclientContentLength =httpRequest.getHeader("X-" +CONTENT_LENGTH);
110-
StringclientMd5 =httpRequest.getHeader("X-" +CONTENT_MD5);
111-
112-
if (clientContentLength !=null) {
113-
byte[]bytes =newbyte[Integer.valueOf(clientContentLength)];
114-
intread =0;
115-
inttotal =0;
116-
while (read > -1) {
117-
read =httpRequest.getInputStream().read(bytes,total,5000);
118-
if (read >0) {
119-
total +=read;
120-
}
121-
}
107+
StringrequestBodyLength =httpRequest.getHeader("X-" +CONTENT_LENGTH);
108+
109+
if (requestBodyLength !=null) {
110+
byte[]requestBodyBytes =IOUtils.toByteArray(httpRequest.getInputStream());
111+
inttotal =requestBodyBytes.length;
122112

123113
httpResponse.addIntHeader("X-" +CONTENT_LENGTH,total);
124-
Stringmd5 =TestUtils.md5(bytes,0,total);
114+
Stringmd5 =TestUtils.md5(requestBodyBytes,0,total);
125115
httpResponse.addHeader(CONTENT_MD5.toString(),md5);
126116

127-
// if (!md5.equals(clientMd5)) {
128-
// int length = total;
129-
// int rows = length / 16 + (length % 15 == 0 ? 0 : 1) + 4;
130-
// StringBuilder buf = new StringBuilder("JETTY".length() + 1 + "JETTY".length() + 2 + 10 + 1 + 2 + rows * 80);
131-
//
132-
// buf.append("JETTY").append(' ').append("JETTY").append(": ").append(length).append('B').append(StringUtil.NEWLINE);
133-
// ByteBufUtil.appendPrettyHexDump(buf, Unpooled.wrappedBuffer(bytes));
134-
// LOGGER.error(buf.toString());
135-
// }
136-
137-
httpResponse.getOutputStream().write(bytes,0,total);
117+
httpResponse.getOutputStream().write(requestBodyBytes,0,total);
138118
}else {
139119
intsize =16384;
140120
if (httpRequest.getContentLength() >0) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp