Skip to content

Commit 6dd1159

Browse files
committed
week3-step1
就后端返回的内容,替换成写死的helloworld
1 parent 01d9794 commit 6dd1159

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎02nio/nio02/src/main/java/io/github/kimmking/gateway/outbound/httpclient4/HttpOutboundHandler.java‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,14 @@ private void handleResponse(final FullHttpRequest fullRequest, final ChannelHand
9595
// response = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(value.getBytes("UTF-8")));
9696
// response.headers().set("Content-Type", "application/json");
9797
// response.headers().setInt("Content-Length", response.content().readableBytes());
98-
99-
98+
//作业第一步,把从后端拿到响应内容,换成写死的helloworld
10099
byte[] body = EntityUtils.toByteArray(endpointResponse.getEntity());
101-
// System.out.println(new String(body));
102-
// System.out.println(body.length);
100+
System.out.println("httpClient proxy got body: " + new String(body));
101+
//写死的替换内容
102+
String homeworkResp = "helloworld";
103+
System.out.println("homework step3, change resp to `helloworld`");
103104

104-
response = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(body));
105+
response = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(homeworkResp.getBytes()));
105106
response.headers().set("Content-Type", "application/json");
106107
response.headers().setInt("Content-Length", Integer.parseInt(endpointResponse.getFirstHeader("Content-Length").getValue()));
107108

0 commit comments

Comments
 (0)