|
13 | 13 | package org.asynchttpclient.netty;
|
14 | 14 |
|
15 | 15 | import io.github.artsok.RepeatedIfExceptionsTest;
|
| 16 | +import io.netty.buffer.ByteBuf; |
| 17 | +import io.netty.buffer.Unpooled; |
16 | 18 | import io.netty.handler.codec.http.DefaultHttpHeaders;
|
17 | 19 | import io.netty.handler.codec.http.HttpHeaders;
|
18 | 20 | import io.netty.handler.codec.http.cookie.Cookie;
|
| 21 | +import org.asynchttpclient.HttpResponseBodyPart; |
19 | 22 |
|
| 23 | +import java.nio.charset.StandardCharsets; |
20 | 24 | import java.text.SimpleDateFormat;
|
21 |
| -import java.util.Date; |
22 |
| -import java.util.List; |
23 |
| -import java.util.Locale; |
24 |
| -import java.util.TimeZone; |
| 25 | +import java.util.*; |
25 | 26 |
|
26 | 27 | import static io.netty.handler.codec.http.HttpHeaderNames.SET_COOKIE;
|
27 | 28 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
@@ -73,4 +74,16 @@ public void testCookieParseWeirdExpiresValue() {
|
73 | 74 | Cookie cookie = cookies.get(0);
|
74 | 75 | assertEquals(Long.MIN_VALUE, cookie.maxAge());
|
75 | 76 | }
|
| 77 | + |
| 78 | + @RepeatedIfExceptionsTest(repeats = 5) |
| 79 | + public void testGetResponseBodyAsByteBuffer() { |
| 80 | + List<HttpResponseBodyPart> bodyParts = new LinkedList<>(); |
| 81 | + bodyParts.add(new LazyResponseBodyPart(Unpooled.wrappedBuffer("Hello ".getBytes()), false)); |
| 82 | + bodyParts.add(new LazyResponseBodyPart(Unpooled.wrappedBuffer("World".getBytes()), true)); |
| 83 | + NettyResponse response = new NettyResponse(new NettyResponseStatus(null, null, null), null, bodyParts); |
| 84 | + |
| 85 | + ByteBuf body = response.getResponseBodyAsByteBuf(); |
| 86 | + assertEquals("Hello World", body.toString(StandardCharsets.UTF_8)); |
| 87 | + body.release(); |
| 88 | + } |
76 | 89 | }
|
0 commit comments