use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project netty by netty.
the class HttpPostMultiPartRequestDecoderTest method testDecodeFullHttpRequestWithNoContentTypeHeader.
@Test
public void testDecodeFullHttpRequestWithNoContentTypeHeader() {
FullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/");
try {
new HttpPostMultipartRequestDecoder(req);
fail("Was expecting an ErrorDataDecoderException");
} catch (HttpPostRequestDecoder.ErrorDataDecoderException expected) {
// expected
} finally {
assertTrue(req.release());
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project netty by netty.
the class HttpPostRequestEncoderTest method testDataIsMultipleOfChunkSize2.
@Test
public void testDataIsMultipleOfChunkSize2() throws Exception {
DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost");
HttpPostRequestEncoder encoder = new HttpPostRequestEncoder(request, true);
int length = 7943;
char[] array = new char[length];
Arrays.fill(array, 'a');
String longText = new String(array);
encoder.addBodyAttribute("foo", longText);
assertNotNull(encoder.finalizeRequest());
checkNextChunkSize(encoder, 8080);
HttpContent httpContent = encoder.readChunk((ByteBufAllocator) null);
assertTrue(httpContent instanceof LastHttpContent, "Expected LastHttpContent is not received");
httpContent.release();
assertTrue(encoder.isEndOfInput(), "Expected end of input is not receive");
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project netty by netty.
the class HttpPostRequestEncoderTest method testSingleFileUploadNoName.
@Test
public void testSingleFileUploadNoName() throws Exception {
DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost");
HttpPostRequestEncoder encoder = new HttpPostRequestEncoder(request, true);
File file1 = new File(getClass().getResource("/file-01.txt").toURI());
encoder.addBodyAttribute("foo", "bar");
encoder.addBodyFileUpload("quux", "", file1, "text/plain", false);
String multipartDataBoundary = encoder.multipartDataBoundary;
String content = getRequestBody(encoder);
String expected = "--" + multipartDataBoundary + "\r\n" + CONTENT_DISPOSITION + ": form-data; name=\"foo\"" + "\r\n" + CONTENT_LENGTH + ": 3" + "\r\n" + CONTENT_TYPE + ": text/plain; charset=UTF-8" + "\r\n" + "\r\n" + "bar" + "\r\n" + "--" + multipartDataBoundary + "\r\n" + CONTENT_DISPOSITION + ": form-data; name=\"quux\"\r\n" + CONTENT_LENGTH + ": " + file1.length() + "\r\n" + CONTENT_TYPE + ": text/plain" + "\r\n" + CONTENT_TRANSFER_ENCODING + ": binary" + "\r\n" + "\r\n" + "File 01" + StringUtil.NEWLINE + "\r\n" + "--" + multipartDataBoundary + "--" + "\r\n";
assertEquals(expected, content);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project netty by netty.
the class HttpPostRequestEncoderTest method testMultiFileUploadInMixedMode.
@Test
public void testMultiFileUploadInMixedMode() throws Exception {
DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost");
HttpPostRequestEncoder encoder = new HttpPostRequestEncoder(request, true);
File file1 = new File(getClass().getResource("/file-01.txt").toURI());
File file2 = new File(getClass().getResource("/file-02.txt").toURI());
File file3 = new File(getClass().getResource("/file-03.txt").toURI());
encoder.addBodyAttribute("foo", "bar");
encoder.addBodyFileUpload("quux", file1, "text/plain", false);
encoder.addBodyFileUpload("quux", file2, "text/plain", false);
encoder.addBodyFileUpload("quux", file3, "text/plain", false);
// We have to query the value of these two fields before finalizing
// the request, which unsets one of them.
String multipartDataBoundary = encoder.multipartDataBoundary;
String multipartMixedBoundary = encoder.multipartMixedBoundary;
String content = getRequestBody(encoder);
String expected = "--" + multipartDataBoundary + "\r\n" + CONTENT_DISPOSITION + ": form-data; name=\"foo\"" + "\r\n" + CONTENT_LENGTH + ": 3" + "\r\n" + CONTENT_TYPE + ": text/plain; charset=UTF-8" + "\r\n" + "\r\n" + "bar" + "\r\n" + "--" + multipartDataBoundary + "\r\n" + CONTENT_DISPOSITION + ": form-data; name=\"quux\"" + "\r\n" + CONTENT_TYPE + ": multipart/mixed; boundary=" + multipartMixedBoundary + "\r\n" + "\r\n" + "--" + multipartMixedBoundary + "\r\n" + CONTENT_DISPOSITION + ": attachment; filename=\"file-01.txt\"" + "\r\n" + CONTENT_LENGTH + ": " + file1.length() + "\r\n" + CONTENT_TYPE + ": text/plain" + "\r\n" + CONTENT_TRANSFER_ENCODING + ": binary" + "\r\n" + "\r\n" + "File 01" + StringUtil.NEWLINE + "\r\n" + "--" + multipartMixedBoundary + "\r\n" + CONTENT_DISPOSITION + ": attachment; filename=\"file-02.txt\"" + "\r\n" + CONTENT_LENGTH + ": " + file2.length() + "\r\n" + CONTENT_TYPE + ": text/plain" + "\r\n" + CONTENT_TRANSFER_ENCODING + ": binary" + "\r\n" + "\r\n" + "File 02" + StringUtil.NEWLINE + "\r\n" + "--" + multipartMixedBoundary + "\r\n" + CONTENT_DISPOSITION + ": attachment; filename=\"file-03.txt\"" + "\r\n" + CONTENT_LENGTH + ": " + file3.length() + "\r\n" + CONTENT_TYPE + ": text/plain" + "\r\n" + CONTENT_TRANSFER_ENCODING + ": binary" + "\r\n" + "\r\n" + "File 03" + StringUtil.NEWLINE + "\r\n" + "--" + multipartMixedBoundary + "--" + "\r\n" + "--" + multipartDataBoundary + "--" + "\r\n";
assertEquals(expected, content);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpRequest in project netty by netty.
the class HttpPostRequestEncoderTest method testHttpPostRequestEncoderSlicedBuffer.
@Test
public void testHttpPostRequestEncoderSlicedBuffer() throws Exception {
DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost");
HttpPostRequestEncoder encoder = new HttpPostRequestEncoder(request, true);
// add Form attribute
encoder.addBodyAttribute("getform", "POST");
encoder.addBodyAttribute("info", "first value");
encoder.addBodyAttribute("secondinfo", "secondvalue a&");
encoder.addBodyAttribute("thirdinfo", "short text");
int length = 100000;
char[] array = new char[length];
Arrays.fill(array, 'a');
String longText = new String(array);
encoder.addBodyAttribute("fourthinfo", longText.substring(0, 7470));
File file1 = new File(getClass().getResource("/file-01.txt").toURI());
encoder.addBodyFileUpload("myfile", file1, "application/x-zip-compressed", false);
encoder.finalizeRequest();
while (!encoder.isEndOfInput()) {
HttpContent httpContent = encoder.readChunk((ByteBufAllocator) null);
ByteBuf content = httpContent.content();
int refCnt = content.refCnt();
assertTrue((content.unwrap() == content || content.unwrap() == null) && refCnt == 1 || content.unwrap() != content && refCnt == 2, "content: " + content + " content.unwrap(): " + content.unwrap() + " refCnt: " + refCnt);
httpContent.release();
}
encoder.cleanFiles();
encoder.close();
}
Aggregations