Refine search
@Override public void apply(Request request, Response response) { try { // do not touch any valid uri: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30 if (url.matches("^\\w+://.*")) { } 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); } }
/** * Change durably the lang for the current user. * * @param lang New Lang object to use * @return true if the requested lang was supported by the application, otherwise false. * * @deprecated Deprecated as of 2.7.0. Use {@link MessagesApi#setLang(Result, Lang)}. */ @Deprecated public boolean changeLang(Lang lang) { if (langs().availables().contains(lang)) { this.lang = lang; scala.Option<String> domain = sessionDomain(); Cookie langCookie = new Cookie(messagesApi().langCookieName(), lang.code(), null, sessionPath(), domain.isDefined() ? domain.get() : null, messagesApi().langCookieSecure(), messagesApi().langCookieHttpOnly(), messagesApi().langCookieSameSite().orElse(null) ); response.setCookie(langCookie); return true; } else { return false; } }
public static Response newResponse() { Response response = new Response(); response.out = new ByteArrayOutputStream(); return response; }
if (Request.current() == null) { domain = host; Request request = Request.createRequest(null, "GET", "/", "", null, null, null, host, false, port, domain, isSecure, null, null); request.body = new ByteArrayInputStream(new byte[0]); if (Response.current() == null) { Response response = new Response(); response.out = new ByteArrayOutputStream(); response.direct = null;
public PlayAsyncIOWriter(final Http.Request request, final Map<String, Object> additionalAttributes, final Http.Response response) { final String[] transport = request.queryString() != null ? request.queryString().get(HeaderConfig.X_ATMOSPHERE_TRANSPORT) : null; this.source = Source.<ByteString>actorRef(BUFFER_SIZE, OverflowStrategy.dropNew()).mapMaterializedValue(actorRef -> { out = new OutStream() { response.setContentType("text/event-stream");
Response response = new Response(); response.out = new ByteArrayOutputStream(); Response.current.set(response); copyResponse(Request.current(), Response.current(), httpServletRequest, httpServletResponse); } else { Invoker.invokeInThread(new ServletInvocation(request, response, httpServletRequest, httpServletResponse));
Http.Request.current.set(new Http.Request()); final Response response = new Response(); Http.Response.current.set(response); response.onWriteChunk(new Action<Object>() {
Http.Response response = context.response(); response.setHeader("Access-Control-Allow-Origin", "*"); if(context.request().method().equals("POST")) { response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE"); response.setHeader("Access-Control-Max-Age", "3600"); response.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization, X-Auth-Token"); response.setHeader("Access-Control-Allow-Credentials", "true"); response.setHeader("Access-Control-Allow-Headers","X-Requested-With, Content-Type, X-Auth-Token"); return delegate.call(context);
@Override public void save(Session session) { if (Http.Response.current() == null) { if (Http.Request.current().cookies.containsKey(COOKIE_PREFIX + "_SESSION") || !SESSION_SEND_ONLY_IF_CHANGED) { Http.Response.current().setCookie(COOKIE_PREFIX + "_SESSION", "", null, "/", 0, COOKIE_SECURE, SESSION_HTTPONLY); String sign = Crypto.sign(sessionData, Play.secretKey.getBytes()); if (COOKIE_EXPIRE == null) { Http.Response.current().setCookie(COOKIE_PREFIX + "_SESSION", sign + "-" + sessionData, null, "/", null, COOKIE_SECURE, SESSION_HTTPONLY); } else { Http.Response.current().setCookie(COOKIE_PREFIX + "_SESSION", sign + "-" + sessionData, null, "/", Time.parseDuration(COOKIE_EXPIRE), COOKIE_SECURE, SESSION_HTTPONLY);
static void save() { if (Http.Response.current() == null) { if(Http.Request.current().cookies.containsKey(Scope.COOKIE_PREFIX + "_ERRORS") || !Scope.SESSION_SEND_ONLY_IF_CHANGED) { Http.Response.current().setCookie(Scope.COOKIE_PREFIX + "_ERRORS", "", null, "/", 0, Scope.COOKIE_SECURE, Scope.SESSION_HTTPONLY); Http.Response.current().setCookie(Scope.COOKIE_PREFIX + "_ERRORS", errorsData, null, "/", null, Scope.COOKIE_SECURE, Scope.SESSION_HTTPONLY); } catch (Exception e) { throw new UnexpectedException("Errors serializationProblem", e);
Response.current().setCookie(cn, "", null, "/", null, Scope.COOKIE_SECURE); String closestLocaleMatch = findClosestMatch(request.acceptLanguage()); if (closestLocaleMatch != null) { set(closestLocaleMatch);
@Override public Result apply(String s) { String fullPath = assetsRootDirectory + s; InputStream inputStream; try { inputStream = new ClassPathResource(fullPath).getInputStream(); } catch (Exception e) { log.debug("Could not find asset: {}", s); return ok(); } catch (Throwable t) { return ok(); } String fileName = FilenameUtils.getName(fullPath); response().setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\""); scala.Option<String> contentType = MimeTypes.forFileName(fileName); String ct; if (contentType.isDefined()) { ct = contentType.get(); } else { ct = "application/octet-stream"; } return ok(inputStream).as(ct); } }
@Override public Result apply(String s) { String fullPath = assetsRootDirectory + s; InputStream inputStream; try { inputStream = new ClassPathResource(fullPath).getInputStream(); } catch (Exception e) { log.debug("Could not find asset: {}", s); return ok(); } catch (Throwable t) { return ok(); } String fileName = FilenameUtils.getName(fullPath); response().setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\""); scala.Option<String> contentType = MimeTypes.forFileName(fileName); String ct; if (contentType.isDefined()) { ct = contentType.get(); } else { ct = "application/octet-stream"; } return ok(inputStream).as(ct); } }
private void refresh(final Request req, Response res, final boolean open) { this.chunks = new Chunks<String>(JavaResults.writeString(Codec.utf_8())) { @Override public void onReady(Chunks.Out<String> oout) { out = oout; out.onDisconnected(new F.Callback0() { @Override public void invoke() throws Throwable { if (!open && out != null) { onClose(); } } }); if (open) { out.close(); onOpen(); } else { String[] value = req.queryString().get("lastEventIds"); retrieveCache(value != null ? value[0] : null); } } }; res.setContentType(longpollContentType() + "; charset=utf-8"); }
@Override public boolean rawInvocation(Request request, Response response) throws Exception { if (request.path.equals("/@db")) { response.status = Http.StatusCode.FOUND; String serverOptions[] = new String[] { }; // For H2 embedded database, we'll also start the Web console if (h2Server != null) { h2Server.stop(); } String domain = request.domain; if (domain.equals("")) { domain = "localhost"; } if (!domain.equals("localhost")) { serverOptions = new String[] {"-webAllowOthers"}; } h2Server = Server.createWebServer(serverOptions); h2Server.start(); response.setHeader("Location", "http://" + domain + ":8082/"); return true; } return false; } }
/** * Add headers to allow cross-domain requests. Be careful, a lot of browsers don't support these features and * will ignore the headers. Refer to the browsers' documentation to know what versions support them. * * @param allowOrigin * a comma separated list of domains allowed to perform the x-domain call, or "*" for all. * @param allowMethods * a comma separated list of HTTP methods allowed, or null for all. * @param allowCredentials * Let the browser send the cookies when doing a x-domain request. Only respected by the browser if * allowOrigin != "*" */ public void accessControl(String allowOrigin, String allowMethods, boolean allowCredentials) { setHeader("Access-Control-Allow-Origin", allowOrigin); if (allowMethods != null) { setHeader("Access-Control-Allow-Methods", allowMethods); } if (allowCredentials == true) { if (allowOrigin.equals("*")) { Logger.warn( "Response.accessControl: When the allowed domain is \"*\", Allow-Credentials is likely to be ignored by the browser."); } setHeader("Access-Control-Allow-Credentials", "true"); } }
@Override public Result apply(String s) { String fullPath = assetsRootDirectory + s; InputStream inputStream; try { inputStream = new ClassPathResource(fullPath).getInputStream(); } catch (Exception e) { log.debug("Could not find asset: {}", s); return ok(); } catch (Throwable t) { return ok(); } String fileName = FilenameUtils.getName(fullPath); response().setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileName + "\""); scala.Option<String> contentType = MimeTypes.forFileName(fileName); String ct; if (contentType.isDefined()) { ct = contentType.get(); } else { ct = "application/octet-stream"; } return ok(inputStream).as(ct); } }
import play.GlobalSettings; import play.libs.F.Promise; import play.mvc.Action; import play.mvc.Http; import play.mvc.Result; public class Global extends GlobalSettings { private class ActionWrapper extends Action.Simple { public ActionWrapper(Action<?> action) { this.delegate = action; } @Override public Promise<Result> call(Http.Context ctx) throws java.lang.Throwable { Promise<Result> result = this.delegate.call(ctx); Http.Response response = ctx.response(); response.setHeader("Access-Control-Allow-Origin", "*"); return result; } } @Override public Action<?> onRequest(Http.Request request, java.lang.reflect.Method actionMethod) { return new ActionWrapper(super.onRequest(request, actionMethod)); } }