mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-21 07:32:54 +01:00
Added ResponseBuilder#setContent(WebResource)
This commit is contained in:
parent
4fd19bbc5e
commit
38bb2ce61c
@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.djrapitops.plan.delivery.web.resolver;
|
package com.djrapitops.plan.delivery.web.resolver;
|
||||||
|
|
||||||
|
import com.djrapitops.plan.delivery.web.resource.WebResource;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
@ -75,6 +76,10 @@ public class ResponseBuilder {
|
|||||||
return setStatus(302).setHeader("Location", url).setContent(new byte[0]);
|
return setStatus(302).setHeader("Location", url).setContent(new byte[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ResponseBuilder setContent(WebResource resource) {
|
||||||
|
return setContent(resource.asBytes());
|
||||||
|
}
|
||||||
|
|
||||||
public ResponseBuilder setContent(byte[] bytes) {
|
public ResponseBuilder setContent(byte[] bytes) {
|
||||||
response.bytes = bytes;
|
response.bytes = bytes;
|
||||||
return setHeader("Content-Length", bytes.length)
|
return setHeader("Content-Length", bytes.length)
|
||||||
|
@ -204,7 +204,7 @@ public class ResponseFactory {
|
|||||||
try {
|
try {
|
||||||
return Response.builder()
|
return Response.builder()
|
||||||
.setMimeType(MimeType.IMAGE)
|
.setMimeType(MimeType.IMAGE)
|
||||||
.setContent(getResource(fileName).asBytes())
|
.setContent(getResource(fileName))
|
||||||
.setStatus(200)
|
.setStatus(200)
|
||||||
.build();
|
.build();
|
||||||
} catch (UncheckedIOException e) {
|
} catch (UncheckedIOException e) {
|
||||||
@ -228,7 +228,7 @@ public class ResponseFactory {
|
|||||||
try {
|
try {
|
||||||
return Response.builder()
|
return Response.builder()
|
||||||
.setMimeType(type)
|
.setMimeType(type)
|
||||||
.setContent(getResource(fileName).asBytes())
|
.setContent(getResource(fileName))
|
||||||
.build();
|
.build();
|
||||||
} catch (UncheckedIOException e) {
|
} catch (UncheckedIOException e) {
|
||||||
return notFound404("Font File not found from jar: " + fileName + ", " + e.toString());
|
return notFound404("Font File not found from jar: " + fileName + ", " + e.toString());
|
||||||
@ -243,7 +243,7 @@ public class ResponseFactory {
|
|||||||
try {
|
try {
|
||||||
return Response.builder()
|
return Response.builder()
|
||||||
.setMimeType(MimeType.FAVICON)
|
.setMimeType(MimeType.FAVICON)
|
||||||
.setContent(getResource("favicon.ico").asBytes())
|
.setContent(getResource("favicon.ico"))
|
||||||
.build();
|
.build();
|
||||||
} catch (UncheckedIOException e) {
|
} catch (UncheckedIOException e) {
|
||||||
return forInternalError(e, "Could not read favicon");
|
return forInternalError(e, "Could not read favicon");
|
||||||
|
Loading…
Reference in New Issue
Block a user