Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Handle charset as part of Content-Type headers (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanf committed Apr 12, 2016
1 parent 46844fb commit c2a5565
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class InvalidContentTypeFilter extends ClientFilter {

// we assume only xml or json are the valid types (wildcard type is also considered compatible)
private static final Pattern VALID_TYPES_REGEX =
Pattern.compile("application/.*\\+?(\\*|xml|json)");
Pattern.compile("application/.*\\+?(\\*|xml|json)(;.*)?");

@Override
public ClientResponse handle(ClientRequest clientRequest)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import org.junit.Test;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.*;
import static org.zanata.rest.client.InvalidContentTypeFilter.isContentTypeCompatible;

public class InvalidContentTypeFilterTest {
// WildFly 8 and 9 have been known to add ";charset=ISO-8859-1" to
// Content-Type headers.
private static final String LATIN_1 = "ISO-8859-1";

private String sampleText =
"<!DOCTYPE composition PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" +
Expand Down Expand Up @@ -61,8 +63,23 @@ public void testValidateContentTypes() {
MatcherAssert.assertThat(
isContentTypeCompatible(MediaType.WILDCARD_TYPE),
equalTo(true));

MediaType zanataXmlType = new MediaType(
"application", "vnd.zanata+xml");
MatcherAssert.assertThat(isContentTypeCompatible(zanataXmlType),
equalTo(true));
MatcherAssert.assertThat(isContentTypeCompatible(
zanataXmlType.withCharset(LATIN_1)),
equalTo(true));

MediaType zanataVersionXmlType = new MediaType(
"application", "vnd.zanata.version+xml");
MatcherAssert.assertThat(isContentTypeCompatible(zanataVersionXmlType),
equalTo(true));
MatcherAssert.assertThat(isContentTypeCompatible(
new MediaType("application", "vnd.zanata+xml")), equalTo(true));
zanataVersionXmlType.withCharset(LATIN_1)),
equalTo(true));

MatcherAssert.assertThat(
isContentTypeCompatible(MediaType.TEXT_PLAIN_TYPE),
equalTo(true));
Expand Down

0 comments on commit c2a5565

Please sign in to comment.