本文整理汇总了Java中play.mvc.Http.Response.setHeader方法的典型用法代码示例。如果您正苦于以下问题:Java Response.setHeader方法的具体用法?Java Response.setHeader怎么用?Java Response.setHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类play.mvc.Http.Response
的用法示例。
在下文中一共展示了Response.setHeader方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getJsonResponse
import play.mvc.Http.Response; //导入方法依赖的package包/类
@Override
public Result getJsonResponse(Object obj, int code, Response response) {
StringWriter w = new StringWriter();
try {
getMapper().writeValue(w, obj);
} catch (Exception e) {
String message = "Error while marshalling the application response";
ApiLog.log.error(message, e);
try {
getMapper().writeValue(w, new ApiError(message));
} catch (Exception exp) {
throw new RuntimeException("Unexpected error while mashalling an ApiError message");
}
code = ERROR_API_RESPONSE_CODE;
}
response.setContentType("application/json");
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Headers", authorizedHeaders);
return Controller.status(code, w.toString());
}
示例2: rawInvocation
import play.mvc.Http.Response; //导入方法依赖的package包/类
@Override
public boolean rawInvocation(Request request, Response response) throws Exception {
if (Play.mode.isDev() && request.path.equals("/@db")) {
response.status = Http.StatusCode.MOVED;
// For H2 embeded database, we'll also start the Web console
if (h2Server != null) {
h2Server.stop();
}
h2Server = org.h2.tools.Server.createWebServer();
h2Server.start();
response.setHeader("Location", "http://localhost:8082/");
return true;
}
return false;
}
示例3: handleDefaultGetHeaders
import play.mvc.Http.Response; //导入方法依赖的package包/类
public static Result handleDefaultGetHeaders(Request request, Response response, String calculatedEtag, String seconds) {
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, HEAD");
response.setHeader("Access-Control-Max-Age", seconds);
response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
response.setHeader("Cache-Control", "public, max-age=" + seconds);
response.setHeader("Expires", new DateTime().plusHours(1).plusSeconds(Integer.parseInt(seconds)).toString(Utils.HTTP_DATE_TIME));
response.setHeader("Last-Modified", new DateTime().plusHours(-1).plusSeconds(-Integer.parseInt(seconds)).toString(Utils.HTTP_DATE_TIME));
response.setHeader("Vary", "Accept-Encoding");
if (calculatedEtag != null) {
response.setHeader("ETag", calculatedEtag);
String eTag = request.getHeader("If-None-Match");
if (calculatedEtag != null && calculatedEtag.equals(eTag)) {
return Results.status(304);
}
}
return null;
}
示例4: call
import play.mvc.Http.Response; //导入方法依赖的package包/类
public F.Promise<Result> call(Context context) throws Throwable {
Response response = context.response();
response.setHeader("Cache-Control","no-cache, no-store, must-revalidate");
response.setHeader("Pragma","no-cache");
response.setHeader("Expires","0");
return delegate.call(context);
}
示例5: call
import play.mvc.Http.Response; //导入方法依赖的package包/类
public F.Promise<Result> call(Context context) throws Throwable {
Response response = context.response();
response.setHeader("Access-Control-Allow-Origin",configuration.value());
if ( context.request().method().equals("OPTIONS")) {
response.setHeader("Access-Control-Allow-Methods","POST, DELETE");
response.setHeader("Access-Control-Max-Age","3600");
response.setHeader("Access-Control-Allow-Headers","Origin, X-Requested-With, Content-Type, Accept, Authorization, Call-Origin");
return F.Promise.pure((Result)ok());
}
response.setHeader("Access-Control-Allow-Headers","X-Requested-With");
return delegate.call(context);
}
示例6: apply
import play.mvc.Http.Response; //导入方法依赖的package包/类
public void apply(Request request, Response response) {
try {
response.status = Http.StatusCode.FOUND;
response.setHeader("Location", file);
} catch (Exception e) {
throw new UnexpectedException(e);
}
}
示例7: apply
import play.mvc.Http.Response; //导入方法依赖的package包/类
public void apply(Request request, Response response) {
try {
if (url.startsWith("http")) {
//
} else if (url.startsWith("/")) {
url = String.format("http%s://%s%s%s", request.secure ? "s" : "", request.domain, (request.port == 80 || request.port == 443) ? "" : ":" + request.port, url);
} else {
url = String.format("http%s://%s%s%s%s", request.secure ? "s" : "", request.domain, (request.port == 80 || request.port == 443) ? "" : ":" + request.port, request.path, request.path.endsWith("/") ? url : "/" + url);
}
response.status = code;
response.setHeader("Location", url);
} catch (Exception e) {
throw new UnexpectedException(e);
}
}
示例8: writeChunk
import play.mvc.Http.Response; //导入方法依赖的package包/类
public void writeChunk(Request playRequest, Response playResponse, ChannelHandlerContext ctx, HttpRequest nettyRequest, Object chunk) {
try {
if (playResponse.direct == null) {
playResponse.setHeader("Transfer-Encoding", "chunked");
playResponse.direct = new LazyChunkedInput();
copyResponse(ctx, playRequest, playResponse, nettyRequest);
}
((LazyChunkedInput) playResponse.direct).writeChunk(chunk);
chunkedWriteHandler.resumeTransfer();
} catch (Exception e) {
throw new UnexpectedException(e);
}
}
示例9: apply
import play.mvc.Http.Response; //导入方法依赖的package包/类
@Override
public void apply(final Request request, final Response response) {
try {
response.status = 206;
Header rangeHeader = request.headers.get("range");
String rangeValue = rangeHeader.value().trim().substring("bytes=".length());
long fileLength = this.file.length();
long start, end;
if (rangeValue.startsWith("-")) {
end = fileLength - 1;
start = fileLength - 1 - Long.parseLong(rangeValue.substring("-".length()));
} else {
String[] range = rangeValue.split("-");
start = Long.parseLong(range[0]);
end = range.length > 1 ? Long.parseLong(range[1]) : fileLength - 1;
}
if (end > fileLength - 1) {
end = fileLength - 1;
}
if (start <= end) {
long contentLength = end - start + 1;
Loggers.Play.debug("Partial download, start: " + start + ", contentLength: " + contentLength);
response.setHeader("Content-Length", contentLength + "");
response.setHeader("Content-Range", "bytes " + start + "-" + end + "/" + fileLength);
response.setHeader("Content-Type", mime);
RandomAccessFile raf = new RandomAccessFile(this.file, "r");
response.direct = new ChunkedFile(raf, start, contentLength, 8192);
}
} catch (Exception e) {
throw new UnexpectedException(e);
}
}
示例10: apply
import play.mvc.Http.Response; //导入方法依赖的package包/类
public void apply(Request request, Response response) {
response.status = Http.StatusCode.NOT_MODIFIED;
if (etag != null) {
response.setHeader("Etag", etag);
}
}
示例11: apply
import play.mvc.Http.Response; //导入方法依赖的package包/类
public void apply(Request request, Response response) {
response.status = Http.StatusCode.UNAUTHORIZED;
response.setHeader("WWW-Authenticate", "Basic realm=\"" + realm + "\"");
}
示例12: handleDefaultPostHeaders
import play.mvc.Http.Response; //导入方法依赖的package包/类
public static void handleDefaultPostHeaders(Request request, Response response) {
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "POST, GET, HEAD");
response.setHeader("Access-Control-Max-Age", "60");
response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
}