@Override public MediaType contentType() { MediaType contentType = response != null ? response.contentType() : null; return U.or(contentType, defaultContentType); }
@Override public synchronized Resp response() { if (response == null) { response = new RespImpl(this); if (defaultContentType != null) { response.contentType(defaultContentType); } } return response; }
@Override public Resp html(Object content) { return contentType(MediaType.HTML_UTF_8).result(content); }
@Override public Resp plain(Object content) { return contentType(MediaType.PLAIN_TEXT_UTF_8).result(content); }
@Override public Resp json(Object content) { return contentType(MediaType.JSON).result(content); }
@Override public Resp binary(Object content) { return contentType(MediaType.BINARY).result(content); }
private void respond(int code, RespBody body) { MediaType contentType = HttpUtils.getDefaultContentType(); if (tokenChanged.get()) { HttpUtils.saveTokenBeforeRenderingHeaders(this, token); } if (sessionChanged.get()) { saveSession(session.decorated()); } if (response != null) { contentType = U.or(response.contentType(), contentType); } renderResponse(code, contentType, body); }
private String validateResponse() { if (response == null) { return "Response wasn't provided!"; } if (response.result() == null && response.body() == null && response.redirect() == null && response.file() == null && response.raw() == null && !response().mvc()) { return "Response content wasn't provided!"; } if (response.contentType() == null && response.raw() == null) { return "Response content type wasn't provided!"; } return null; }
private void saveToCache() { U.must(posBeforeBody != UNDEFINED); Buf out = channel.output(); int posAfterBody = out.size(); int bodyLength = (int) (posAfterBody - posBeforeBody); // FIXME validate '\r\n\r\n' before the start position of the response body Cache<HTTPCacheKey, CachedResp> cache = route.cache(); U.notNull(cache, "route.cache"); SimpleHttpResp proxyResp = new SimpleHttpResp(); proxyResp.cookies = U.map(U.safe(response != null ? response.cookies() : null)); Map<String, String> headers = response != null ? response.headers() : Collections.emptyMap(); HttpUtils.proxyResponseHeaders(headers, proxyResp); proxyResp.code = response != null ? response.code() : 200; if (proxyResp.contentType == null) { proxyResp.contentType = response != null ? response.contentType() : defaultContentType; } // don't cache the response if it contains cookies or token data if (U.notEmpty(proxyResp.cookies) || hasToken()) return; ByteBuffer body = writeBodyToBuf(out, bodyLength); CachedResp cached = new CachedResp(proxyResp.code, proxyResp.contentType, proxyResp.headers, body); cache.set(cacheKey, cached); }
@Override public MediaType contentType() { MediaType contentType = response != null ? response.contentType() : null; return U.or(contentType, defaultContentType); }
@Override public Resp html(Object content) { return contentType(MediaType.HTML_UTF_8).result(content); }
@Override public synchronized Resp response() { if (response == null) { response = new RespImpl(this); if (defaultContentType != null) { response.contentType(defaultContentType); } } return response; }
@Override public Resp plain(Object content) { return contentType(MediaType.PLAIN_TEXT_UTF_8).result(content); }
@Override public Resp json(Object content) { return contentType(MediaType.JSON).result(content); }
@Override public Resp binary(Object content) { return contentType(MediaType.BINARY).result(content); }
private void respond(int code, RespBody body) { MediaType contentType = HttpUtils.getDefaultContentType(); if (tokenChanged.get()) { HttpUtils.saveTokenBeforeRenderingHeaders(this, token); } if (sessionChanged.get()) { saveSession(session.decorated()); } if (response != null) { contentType = U.or(response.contentType(), contentType); } renderResponse(code, contentType, body); }
private String validateResponse() { if (response == null) { return "Response wasn't provided!"; } if (response.result() == null && response.body() == null && response.redirect() == null && response.file() == null && response.raw() == null && !response().mvc()) { return "Response content wasn't provided!"; } if (response.contentType() == null && response.raw() == null) { return "Response content type wasn't provided!"; } return null; }
private void saveToCache() { U.must(posBeforeBody != UNDEFINED); Buf out = channel.output(); int posAfterBody = out.size(); int bodyLength = (int) (posAfterBody - posBeforeBody); // FIXME validate '\r\n\r\n' before the start position of the response body Cache<HTTPCacheKey, CachedResp> cache = route.cache(); U.notNull(cache, "route.cache"); SimpleHttpResp proxyResp = new SimpleHttpResp(); proxyResp.cookies = U.map(U.safe(response != null ? response.cookies() : null)); Map<String, String> headers = response != null ? response.headers() : Collections.<String, String>emptyMap(); HttpUtils.proxyResponseHeaders(headers, proxyResp); proxyResp.code = response != null ? response.code() : 200; if (proxyResp.contentType == null) { proxyResp.contentType = response != null ? response.contentType() : defaultContentType; } // don't cache the response if it contains cookies or token data if (U.notEmpty(proxyResp.cookies) || hasToken()) return; ByteBuffer body = writeBodyToBuf(out, bodyLength); CachedResp cached = new CachedResp(proxyResp.code, proxyResp.contentType, proxyResp.headers, body); cache.set(cacheKey, cached); }