Skip to content

Commit

Permalink
minor clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
slandelle committed Jun 9, 2017
1 parent 3c25a42 commit 3abe37b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 36 deletions.
Expand Up @@ -75,22 +75,23 @@ public void testConnectionDoesNotGetClosed() throws Exception {
assertEquals(response.getStatusCode(), 200);
byte[] responseBody = response.getResponseBodyAsBytes();
responseBody = response.getResponseBodyAsBytes();
assertEquals(Integer.valueOf(response.getHeader("X-" + CONTENT_LENGTH)).intValue(), LARGE_IMAGE_BYTES.length, "Server received payload length invalid");
assertEquals(responseBody.length, LARGE_IMAGE_BYTES.length, "Client back payload length invalid");
assertEquals(response.getHeader(CONTENT_MD5), expectedMd5, "Server received payload MD5 invalid");
assertEquals(TestUtils.md5(responseBody), expectedMd5, "Client back payload MD5 invalid");
assertEquals(Integer.valueOf(response.getHeader("X-" + CONTENT_LENGTH)).intValue(), LARGE_IMAGE_BYTES.length, "Server side payload length invalid");
assertEquals(responseBody.length, LARGE_IMAGE_BYTES.length, "Client side payload length invalid");
assertEquals(response.getHeader(CONTENT_MD5), expectedMd5, "Server side payload MD5 invalid");
assertEquals(TestUtils.md5(responseBody), expectedMd5, "Client side payload MD5 invalid");
assertEquals(responseBody, LARGE_IMAGE_BYTES);

response = requestBuilder.execute().get();
assertEquals(response.getStatusCode(), 200);
responseBody = response.getResponseBodyAsBytes();
assertEquals(Integer.valueOf(response.getHeader("X-" + CONTENT_LENGTH)).intValue(), LARGE_IMAGE_BYTES.length, "Server received payload length invalid");
assertEquals(responseBody.length, LARGE_IMAGE_BYTES.length, "Client back payload length invalid");
assertEquals(Integer.valueOf(response.getHeader("X-" + CONTENT_LENGTH)).intValue(), LARGE_IMAGE_BYTES.length, "Server side payload length invalid");
assertEquals(responseBody.length, LARGE_IMAGE_BYTES.length, "Client side payload length invalid");
try {
assertEquals(response.getHeader(CONTENT_MD5), expectedMd5, "Server received payload MD5 invalid");
assertEquals(TestUtils.md5(responseBody), expectedMd5, "Client back payload MD5 invalid");
assertEquals(response.getHeader(CONTENT_MD5), expectedMd5, "Server side payload MD5 invalid");
assertEquals(TestUtils.md5(responseBody), expectedMd5, "Client side payload MD5 invalid");
assertEquals(responseBody, LARGE_IMAGE_BYTES);
} catch (AssertionError e) {
e.printStackTrace();
for (int i = 0; i < LARGE_IMAGE_BYTES.length; i++) {
assertEquals(responseBody[i], LARGE_IMAGE_BYTES[i], "Invalid response byte at position " + i);
}
Expand Down
36 changes: 8 additions & 28 deletions client/src/test/java/org/asynchttpclient/test/EchoHandler.java
Expand Up @@ -14,9 +14,6 @@
package org.asynchttpclient.test;

import static io.netty.handler.codec.http.HttpHeaderNames.*;
import io.netty.buffer.ByteBufUtil;
import io.netty.buffer.Unpooled;
import io.netty.util.internal.StringUtil;

import java.io.IOException;
import java.util.Enumeration;
Expand All @@ -26,6 +23,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.slf4j.Logger;
Expand Down Expand Up @@ -106,35 +104,17 @@ public void handle(String pathInContext, Request request, HttpServletRequest htt
}
}

String clientContentLength = httpRequest.getHeader("X-" + CONTENT_LENGTH);
String clientMd5 = httpRequest.getHeader("X-" + CONTENT_MD5);

if (clientContentLength != null) {
byte[] bytes = new byte[Integer.valueOf(clientContentLength)];
int read = 0;
int total = 0;
while (read > -1) {
read = httpRequest.getInputStream().read(bytes, total, 5000);
if (read > 0) {
total += read;
}
}
String requestBodyLength = httpRequest.getHeader("X-" + CONTENT_LENGTH);

if (requestBodyLength != null) {
byte[] requestBodyBytes = IOUtils.toByteArray(httpRequest.getInputStream());
int total = requestBodyBytes.length;

httpResponse.addIntHeader("X-" + CONTENT_LENGTH, total);
String md5 = TestUtils.md5(bytes, 0, total);
String md5 = TestUtils.md5(requestBodyBytes, 0, total);
httpResponse.addHeader(CONTENT_MD5.toString(), md5);

// if (!md5.equals(clientMd5)) {
// int length = total;
// int rows = length / 16 + (length % 15 == 0 ? 0 : 1) + 4;
// StringBuilder buf = new StringBuilder("JETTY".length() + 1 + "JETTY".length() + 2 + 10 + 1 + 2 + rows * 80);
//
// buf.append("JETTY").append(' ').append("JETTY").append(": ").append(length).append('B').append(StringUtil.NEWLINE);
// ByteBufUtil.appendPrettyHexDump(buf, Unpooled.wrappedBuffer(bytes));
// LOGGER.error(buf.toString());
// }

httpResponse.getOutputStream().write(bytes, 0, total);
httpResponse.getOutputStream().write(requestBodyBytes, 0, total);
} else {
int size = 16384;
if (httpRequest.getContentLength() > 0) {
Expand Down

0 comments on commit 3abe37b

Please sign in to comment.