Java Code Examples for io.netty.handler.codec.http.DefaultFullHttpRequest#release()
The following examples show how to use
io.netty.handler.codec.http.DefaultFullHttpRequest#release() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpPostRequestDecoderTest.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Test public void testMultipartRequestWithFileInvalidCharset() throws Exception { final String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO"; final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost"); req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary); // Force to use memory-based data. final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false); final String data = "asdf"; final String filename = "tmp;0.txt"; final String body = "--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"file\"; filename=\"" + filename + "\"\r\n" + "Content-Type: image/gif; charset=ABCD\r\n" + "\r\n" + data + "\r\n" + "--" + boundary + "--\r\n"; req.content().writeBytes(body.getBytes(CharsetUtil.UTF_8)); // Create decoder instance to test. try { new HttpPostRequestDecoder(inMemoryFactory, req); fail("Was expecting an ErrorDataDecoderException"); } catch (HttpPostRequestDecoder.ErrorDataDecoderException e) { assertTrue(e.getCause() instanceof UnsupportedCharsetException); } finally { req.release(); } }
Example 2
Source File: HttpPostRequestDecoderTest.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Test public void testMultipartRequestWithFieldInvalidCharset() throws Exception { final String boundary = "dLV9Wyq26L_-JQxk6ferf-RT153LhOO"; final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost"); req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary); // Force to use memory-based data. final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false); final String aData = "some data would be here. the data should be long enough that it " + "will be longer than the original buffer length of 256 bytes in " + "the HttpPostRequestDecoder in order to trigger the issue. Some more " + "data just to be on the safe side."; final String body = "--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"root\"\r\n" + "Content-Type: text/plain; charset=ABCD\r\n" + "\r\n" + aData + "\r\n" + "--" + boundary + "--\r\n"; req.content().writeBytes(body.getBytes(CharsetUtil.UTF_8)); // Create decoder instance to test. try { new HttpPostRequestDecoder(inMemoryFactory, req); fail("Was expecting an ErrorDataDecoderException"); } catch (HttpPostRequestDecoder.ErrorDataDecoderException e) { assertTrue(e.getCause() instanceof UnsupportedCharsetException); } finally { req.release(); } }
Example 3
Source File: HttpPostRequestDecoderTest.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Test public void testDecodeContentDispositionFieldParameters() throws Exception { final String boundary = "74e78d11b0214bdcbc2f86491eeb4902"; String encoding = "utf-8"; String filename = "attached_файл.txt"; String filenameEncoded = URLEncoder.encode(filename, encoding); final String body = "--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"file\"; filename*=" + encoding + "''" + filenameEncoded + "\r\n" + "\r\n" + "foo\r\n" + "\r\n" + "--" + boundary + "--"; final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost", Unpooled.wrappedBuffer(body.getBytes())); req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary); final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false); final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req); assertFalse(decoder.getBodyHttpDatas().isEmpty()); InterfaceHttpData part1 = decoder.getBodyHttpDatas().get(0); assertTrue("the item should be a FileUpload", part1 instanceof FileUpload); FileUpload fileUpload = (FileUpload) part1; assertEquals("the filename should be decoded", filename, fileUpload.getFilename()); decoder.destroy(); req.release(); }
Example 4
Source File: HttpPostRequestDecoderTest.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Test public void testDecodeWithLanguageContentDispositionFieldParameters() throws Exception { final String boundary = "74e78d11b0214bdcbc2f86491eeb4902"; String encoding = "utf-8"; String filename = "attached_файл.txt"; String language = "anything"; String filenameEncoded = URLEncoder.encode(filename, encoding); final String body = "--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"file\"; filename*=" + encoding + "'" + language + "'" + filenameEncoded + "\r\n" + "\r\n" + "foo\r\n" + "\r\n" + "--" + boundary + "--"; final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost", Unpooled.wrappedBuffer(body.getBytes())); req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary); final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false); final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(inMemoryFactory, req); assertFalse(decoder.getBodyHttpDatas().isEmpty()); InterfaceHttpData part1 = decoder.getBodyHttpDatas().get(0); assertTrue("the item should be a FileUpload", part1 instanceof FileUpload); FileUpload fileUpload = (FileUpload) part1; assertEquals("the filename should be decoded", filename, fileUpload.getFilename()); decoder.destroy(); req.release(); }
Example 5
Source File: HttpPostRequestDecoderTest.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Test public void testDecodeMalformedNotEncodedContentDispositionFieldParameters() throws Exception { final String boundary = "74e78d11b0214bdcbc2f86491eeb4902"; final String body = "--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"file\"; filename*=not-encoded\r\n" + "\r\n" + "foo\r\n" + "\r\n" + "--" + boundary + "--"; final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost", Unpooled.wrappedBuffer(body.getBytes())); req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary); final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false); try { new HttpPostRequestDecoder(inMemoryFactory, req); fail("Was expecting an ErrorDataDecoderException"); } catch (HttpPostRequestDecoder.ErrorDataDecoderException e) { assertTrue(e.getCause() instanceof ArrayIndexOutOfBoundsException); } finally { req.release(); } }
Example 6
Source File: HttpPostRequestDecoderTest.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Test public void testDecodeMalformedBadCharsetContentDispositionFieldParameters() throws Exception { final String boundary = "74e78d11b0214bdcbc2f86491eeb4902"; final String body = "--" + boundary + "\r\n" + "Content-Disposition: form-data; name=\"file\"; filename*=not-a-charset''filename\r\n" + "\r\n" + "foo\r\n" + "\r\n" + "--" + boundary + "--"; final DefaultFullHttpRequest req = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost", Unpooled.wrappedBuffer(body.getBytes())); req.headers().add(HttpHeaderNames.CONTENT_TYPE, "multipart/form-data; boundary=" + boundary); final DefaultHttpDataFactory inMemoryFactory = new DefaultHttpDataFactory(false); try { new HttpPostRequestDecoder(inMemoryFactory, req); fail("Was expecting an ErrorDataDecoderException"); } catch (HttpPostRequestDecoder.ErrorDataDecoderException e) { assertTrue(e.getCause() instanceof UnsupportedCharsetException); } finally { req.release(); } }