-
Notifications
You must be signed in to change notification settings - Fork 190
Enable multipart/related on FileUpload #315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fb332ce
added ability to use content-type: multipart/related
mufasa1976 6e4e9eb
Merge branch 'apache:master' into master
mufasa1976 148bfaf
added entry to src/changes/changes.xml; removed unnecessary paragraph…
mufasa1976 96e3573
fixing checkstyle failures
mufasa1976 9945131
fixed findings of review
mufasa1976 8cc58eb
added MockRequestContextTest
mufasa1976 76a84fa
added License Header
mufasa1976 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
187 changes: 187 additions & 0 deletions
187
...pload2-core/src/test/java/org/apache/commons/fileupload2/core/MockRequestContextTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,187 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.commons.fileupload2.core; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.io.InputStream; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.nio.charset.UnsupportedCharsetException; | ||
| import java.util.function.Function; | ||
| import java.util.function.LongSupplier; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| /** | ||
| * Tests for {@link AbstractRequestContext} | ||
| */ | ||
| public class MockRequestContextTest { | ||
| /** | ||
| * Test if the <code>content-length</code> Value is numeric. | ||
| */ | ||
| @Test | ||
| public void getContentLengthByParsing() { | ||
| final RequestContext request = new MockRequestContext( | ||
| x -> "1234", | ||
| () -> 5678L, | ||
| "Request", | ||
| "US-ASCII", | ||
| "text/plain", | ||
| null); | ||
| assertEquals(1234L, request.getContentLength()); | ||
| } | ||
|
|
||
| /** | ||
| * Test if the <code>content-length</code> Value is not numeric | ||
| * and the Default will be taken. | ||
| */ | ||
| @Test | ||
| public void getContentLengthDefaultBecauseOfInvalidNumber() { | ||
| final RequestContext request = new MockRequestContext( | ||
| x -> "not-a-number", | ||
| () -> 5678L, | ||
| "Request", | ||
| "US-ASCII", | ||
| "text/plain", | ||
| null); | ||
| assertEquals(5678L, request.getContentLength()); | ||
| } | ||
|
|
||
| /** | ||
| * Test if the given <code>character-encoding</code> is a valid CharEncoding | ||
| */ | ||
| @Test | ||
| public void getCharset() { | ||
| final RequestContext request = new MockRequestContext( | ||
| x -> "1234", | ||
| () -> 5678L, | ||
| "Request", | ||
| "US-ASCII", | ||
| "text/plain", | ||
| null); | ||
| assertEquals(StandardCharsets.US_ASCII, request.getCharset()); | ||
| } | ||
|
|
||
| /** | ||
| * Test if the given <code>character-encoding</code> is an invalid CharEncoding | ||
| * and leads to {@link UnsupportedCharsetException} | ||
| */ | ||
| @Test | ||
| public void getInvalidCharset() { | ||
| final RequestContext request = new MockRequestContext( | ||
| x -> "1234", | ||
| () -> 5678L, | ||
| "Request", | ||
| "invalid-charset", | ||
| "text/plain", | ||
| null); | ||
| assertThrows(UnsupportedCharsetException.class, request::getCharset); | ||
| } | ||
|
|
||
| /** | ||
| * Test the <code>toString()</code> Output | ||
| */ | ||
| @Test | ||
| public void testToString() { | ||
| final RequestContext request = new MockRequestContext( | ||
| x -> "1234", | ||
| () -> 5678L, | ||
| "Request", | ||
| "US-ASCII", | ||
| "text/plain", | ||
| null); | ||
| assertEquals("MockRequestContext [ContentLength=1234, ContentType=text/plain]", request.toString()); | ||
| } | ||
|
|
||
| /** | ||
| * Test if the <code>content-type</code> is <code>multipart/related</code> | ||
| */ | ||
| @Test | ||
| public void testIsMultipartRelated() { | ||
| final RequestContext request = new MockRequestContext( | ||
| x -> "1234", | ||
| () -> 5678L, | ||
| "Request", | ||
| "US-ASCII", | ||
| "multipart/related; boundary=---1234; type=\"application/xop+xml\"; start-info=\"application/soap+xml\"", | ||
| null); | ||
| assertTrue(request.isMultipartRelated()); | ||
| } | ||
|
|
||
| /** | ||
| * Test if the <code>content-type</code> is not <code>multipart/related</code> | ||
| */ | ||
| @Test | ||
| public void testIsNotMultipartRelated() { | ||
| final RequestContext request = new MockRequestContext( | ||
| x -> "1234", | ||
| () -> 5678L, | ||
| "Request", | ||
| "US-ASCII", | ||
| "text/plain", | ||
| null); | ||
| assertFalse(request.isMultipartRelated()); | ||
| } | ||
|
|
||
| private static final class MockRequestContext extends AbstractRequestContext<Object> { | ||
| private final String characterEncoding; | ||
| private final String contentType; | ||
| private final InputStream inputStream; | ||
|
|
||
| private MockRequestContext(Function<String, String> contentLengthString, | ||
| LongSupplier contentLengthDefault, | ||
| Object request, | ||
| String characterEncoding, | ||
| String contentType, | ||
| InputStream inputStream) { | ||
| super(contentLengthString, contentLengthDefault, request); | ||
| this.characterEncoding = characterEncoding; | ||
| this.contentType = contentType; | ||
| this.inputStream = inputStream; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the character encoding for the request. | ||
| * | ||
| * @return The character encoding for the request. | ||
| */ | ||
| @Override | ||
| public String getCharacterEncoding() { | ||
| return characterEncoding; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the content type of the request. | ||
| * | ||
| * @return The content type of the request. | ||
| */ | ||
| @Override | ||
| public String getContentType() { | ||
| return contentType; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the input stream for the request. | ||
| * | ||
| * @return The input stream for the request. | ||
| */ | ||
| @Override | ||
| public InputStream getInputStream() { | ||
| return inputStream; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.