-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
request body should not be reset - some controllers might need to rea…
…d it
- Loading branch information
Showing
3 changed files
with
34 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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 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,30 @@ | ||
package play.data.parsing; | ||
|
||
import org.junit.Test; | ||
import play.mvc.Http; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
import static org.apache.commons.io.IOUtils.toByteArray; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class TextParserTest { | ||
TextParser parser = new TextParser(); | ||
|
||
@Test | ||
public void parsesRequestBodyAsText() throws IOException { | ||
Http.Request request = new Http.Request(); | ||
request.encoding = UTF_8.name(); | ||
request.body = new ByteArrayInputStream("Don't reset me please".getBytes(UTF_8)); | ||
|
||
assertThat(parser.parse(request).get("body")) | ||
.as("returns request body as <'body', body> map") | ||
.isEqualTo(new String[] {"Don't reset me please"}); | ||
|
||
assertThat(toByteArray(request.body)) | ||
.as("Important: request body should not be reset - some controllers might need to read it") | ||
.isEqualTo("Don't reset me please".getBytes(UTF_8)); | ||
} | ||
} |