@Override public Response.ResponseBuilder header(String name, Object value) { response.headers().set(name, value); return this; }
/** * Send a 303 (See Other) redirect * * @param to the location to redirect to */ public void redirect(String to) { setStatus(HttpResponseStatus.SEE_OTHER); headers().set("Location", to); redirect = true; }
public void clearHeaders() { newCookies.clear(); headers().clear(); }
/** * Initializes a response with 200 status and sets the connection header to whatever the client * requested. If no connection header is found in the client request then it is set to CLOSE * * @param message */ public HttpResponse(final HttpRequest message) { this(message == null ? HttpVersion.HTTP_1_1 : message.getProtocolVersion(), HttpStatus.OK); if (message != null) { String conn = message.headers().get(HttpHeaders.Names.CONNECTION); if (conn == null) { conn = HttpHeaders.Values.CLOSE; } headers().set(HttpHeaders.Names.CONNECTION, conn); } }
/** * sets any overridden headers */ public void finalizeCustomHeaders(HttpRequest request) { if (newCookies.size() > 0 || request.isNewSession()) { HashMap<String, HttpCookie> cookies = new HashMap<>(); HttpCookie cookie = request.getSessionCookie(); //if it's a new session or the session cookie isn't set on the request then tell the client to set it if (cookie != null && (request.isNewSession() || request.getCookie(HttpRequest.SID) == null)) { cookies.put(cookie.getName(), cookie); } cookies.putAll(newCookies); headers().set(HttpHeaders.Names.SET_COOKIE, ServerCookieEncoder.encode(new ArrayList<Cookie>(cookies.values()))); } }
ByteBuf buffer = Unpooled.copiedBuffer(buf, CharsetUtil.UTF_8); higgsPreparedResponse.content().writeBytes(buffer); higgsPreparedResponse.headers().set(CONTENT_TYPE, "text/html; charset=UTF-8"); HttpHeaders.setContentLength(res, buffer.writerIndex()); HttpHeaders.setKeepAlive(res, false);
ByteBuf buffer = Unpooled.copiedBuffer(buf, CharsetUtil.UTF_8); higgsPreparedResponse.content().writeBytes(buffer); higgsPreparedResponse.headers().set(CONTENT_TYPE, "text/html; charset=UTF-8"); HttpHeaders.setContentLength(res, buffer.writerIndex()); HttpHeaders.setKeepAlive(res, false);