Skip to content

Commit

Permalink
Removed encoding info from the JSON content type headers.
Browse files Browse the repository at this point in the history
  • Loading branch information
nmihajlovski committed Aug 25, 2016
1 parent d093c55 commit 5151592
Show file tree
Hide file tree
Showing 135 changed files with 140 additions and 140 deletions.
Expand Up @@ -86,8 +86,8 @@ public class MediaType extends RapidoidThing {
public static final MediaType APPLICATION_JAVA_SERIALIZED_OBJECT = create("application/java-serialized-object",
"ser");
public static final MediaType APPLICATION_JAVA_VM = create("application/java-vm", "class");
public static final MediaType APPLICATION_JSON_UTF8 = createUTF8("application/json", "json", "map");
public static final MediaType APPLICATION_JSONML_JSON_UTF8 = createUTF8("application/jsonml+json", "jsonml");
public static final MediaType APPLICATION_JSON = create("application/json", "json", "map");
public static final MediaType APPLICATION_JSONML_JSON = create("application/jsonml+json", "jsonml");
public static final MediaType APPLICATION_LOST_XML = create("application/lost+xml", "lostxml");
public static final MediaType APPLICATION_M3G = create("application/m3g", "m3g");
public static final MediaType APPLICATION_MAC_BINHEX40 = create("application/mac-binhex40", "hqx");
Expand Down Expand Up @@ -1166,7 +1166,7 @@ public class MediaType extends RapidoidThing {

public static final MediaType XHTML_XML_UTF8 = APPLICATION_XHTML_XML_UTF8;
public static final MediaType JAVASCRIPT_UTF8 = APPLICATION_JAVASCRIPT_UTF8;
public static final MediaType JSON_UTF_8 = APPLICATION_JSON_UTF8;
public static final MediaType JSON = APPLICATION_JSON;
public static final MediaType XML_UTF_8 = APPLICATION_XML_UTF8;

public static final MediaType BINARY = APPLICATION_OCTET_STREAM;
Expand Down Expand Up @@ -1280,7 +1280,7 @@ public String info() {
return "html";
}

if (this == JSON_UTF_8) {
if (this == JSON) {
return "json";
}

Expand Down
Expand Up @@ -293,7 +293,7 @@ public static String constructUrl(Req x, String path) {
}

public static byte[] responseToBytes(Req req, Object result, MediaType contentType, JsonResponseRenderer jsonRenderer) {
if (U.eq(contentType, MediaType.JSON_UTF_8)) {
if (U.eq(contentType, MediaType.JSON)) {
ByteArrayOutputStream out = new ByteArrayOutputStream();

try {
Expand Down
Expand Up @@ -212,7 +212,7 @@ public interface Resp {
/**
* Sets the <b><code>Content-Type: application/json; charset=utf-8</code> header and the content</b> of the HTTP
* response. <br>
* <i>Alias</i> to <code>contentType(MediaType.JSON_UTF_8).body(content)</code>.
* <i>Alias</i> to <code>contentType(MediaType.JSON).body(content)</code>.
*/
Resp json(Object content);

Expand Down
Expand Up @@ -56,7 +56,7 @@ public Object handleError(Req req, Resp resp, Throwable error) {

private Object renderError(Req req, Resp resp, Throwable error) {

if (resp.contentType() == MediaType.JSON_UTF_8) {
if (resp.contentType() == MediaType.JSON) {
return HttpUtils.getErrorInfo(resp, error);

} else if (resp.contentType() == MediaType.PLAIN_TEXT_UTF_8) {
Expand Down Expand Up @@ -105,7 +105,7 @@ protected Object defaultErrorHandling(Req req, Throwable error) {
if (error instanceof NotFound) {
Resp resp = req.response().code(404);

if (resp.contentType() == MediaType.JSON_UTF_8) {
if (resp.contentType() == MediaType.JSON) {
return error;
} else {
return resp.view("404").result(Collections.emptyMap());
Expand Down
Expand Up @@ -79,7 +79,7 @@ protected String contentTypeInfo(String inside) {
if (contentType == MediaType.HTML_UTF_8) {
type = options.mvc() ? "mvc" : "html";

} else if (contentType == MediaType.JSON_UTF_8) {
} else if (contentType == MediaType.JSON) {
type = "json";

} else if (contentType == MediaType.PLAIN_TEXT_UTF_8) {
Expand Down
Expand Up @@ -170,7 +170,7 @@ public static void writeContentLengthAndBody(Channel ctx, byte[] content) {
}

public static void writeAsJson(Channel ctx, int code, boolean isKeepAlive, Object value) {
startResponse(ctx, code, isKeepAlive, MediaType.JSON_UTF_8);
startResponse(ctx, code, isKeepAlive, MediaType.JSON);

Buf out = ctx.output();

Expand Down
Expand Up @@ -299,7 +299,7 @@ public Resp plain(Object content) {

@Override
public Resp json(Object content) {
return contentType(MediaType.JSON_UTF_8).result(content);
return contentType(MediaType.JSON).result(content);
}

@Override
Expand Down
Expand Up @@ -350,7 +350,7 @@ private RouteOptions htmlOpts() {
}

private RouteOptions jsonOpts() {
return opts(MediaType.JSON_UTF_8);
return opts(MediaType.JSON);
}

private RouteOptions plainOpts() {
Expand Down
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 404 Not Found
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 86

{"error":"The requested resource could not be found!","code":404,"status":"Not Found"}
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 500 Internal Server Error
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 8

"MY NPE"
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 500 Internal Server Error
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 8

"ON SEC"
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 500 Internal Server Error
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 70

{"error":"out of memory!","code":500,"status":"Internal Server Error"}
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 500 Internal Server Error
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 8

"MY RTE"
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 200 OK
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 66

{"custom":"","uri":"/abc?custom","parsed":{"x":13579,"foo":"bar"}}
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 200 OK
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 40

{"multipart":"","x":"13579","foo":"bar"}
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 200 OK
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 25

{"id":1,"the-name":"one"}
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 200 OK
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 28

{"id":-1,"the-name":"three"}
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 200 OK
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 25

{"id":2,"the-name":"two"}
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 200 OK
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 27

{"id":-1,"the-name":"four"}
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 200 OK
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 31

{
Expand Down
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 200 OK
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 20

{"foo":12,"bar":345}
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 200 OK
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 17

"admin /b:admin:"
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 403 Forbidden
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 85

{"error":"The user doesn't have the required roles!","code":403,"status":"Forbidden"}
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 200 OK
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 17

"admin /b:admin:"
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 403 Forbidden
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 85

{"error":"The user doesn't have the required roles!","code":403,"status":"Forbidden"}
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 403 Forbidden
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 85

{"error":"The user doesn't have the required roles!","code":403,"status":"Forbidden"}
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 500 Internal Server Error
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 64

{"error":"Invalid!","code":500,"status":"Internal Server Error"}
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 422 Unprocessable Entity
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 68

{"error":"Invalid data!","code":422,"status":"Unprocessable Entity"}
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 422 Unprocessable Entity
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 73

{"error":"Validation failed!","code":422,"status":"Unprocessable Entity"}
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 200 OK
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 22

{"id":null,"num":null}
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 200 OK
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 21

{"id":null,"num":123}
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 422 Unprocessable Entity
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 99

{"error":"Validation failed: Foo.num (may not be null)","code":422,"status":"Unprocessable Entity"}
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 200 OK
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 21

{"id":null,"num":123}
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 422 Unprocessable Entity
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 99

{"error":"Validation failed: Foo.num (may not be null)","code":422,"status":"Unprocessable Entity"}
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 200 OK
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 18

{"id":1,"num":123}
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 200 OK
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 8

"GET /b"
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 403 Forbidden
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 55

{"error":"Not secure!","code":403,"status":"Forbidden"}
Expand Up @@ -2,7 +2,7 @@ HTTP/1.1 200 OK
Connection: keep-alive
Server: Rapidoid
Date: XXXXX GMT
Content-Type: application/json; charset=utf-8
Content-Type: application/json
Content-Length: 10

"RESULT 5"

0 comments on commit 5151592

Please sign in to comment.