@Override public RequestFixture header(CharSequence name, String value) { requestHeaders.add(name, value); return this; }
@Override public MutableHeaders add(CharSequence name, Object value) { if (!contentTypeSet && (name == CONTENT_TYPE || name.toString().equalsIgnoreCase(CONTENT_TYPE.toString()))) { contentTypeSet = true; } wrapped.add(name, value); return this; }
private void setCookieHeader() { if (cookies != null && !cookies.isEmpty()) { for (Cookie cookie : cookies) { headers.add(HttpHeaderConstants.SET_COOKIE, ServerCookieEncoder.STRICT.encode(cookie)); } } }
/** * {@inheritDoc} */ @Override public void render(Context context) throws Exception { ByteBufAllocator bufferAllocator = context.get(ByteBufAllocator.class); Response response = context.getResponse(); response.getHeaders().add(HttpHeaderConstants.CONTENT_TYPE, HttpHeaderConstants.TEXT_EVENT_STREAM_CHARSET_UTF_8); response.getHeaders().add(HttpHeaderConstants.TRANSFER_ENCODING, HttpHeaderConstants.CHUNKED); response.getHeaders().add(HttpHeaderConstants.CACHE_CONTROL, HttpHeaderConstants.NO_CACHE_FULL); response.getHeaders().add(HttpHeaderConstants.PRAGMA, HttpHeaderConstants.NO_CACHE); response.sendStream(Streams.map(publisher, i -> ServerSentEventEncoder.INSTANCE.encode(i, bufferAllocator))); }
private void applyCookies(RequestSpec requestSpec) { List<Cookie> requestCookies = getCookies(requestSpec.getUri().getPath()); String encodedCookie = requestCookies.isEmpty() ? "" : ClientCookieEncoder.STRICT.encode(requestCookies); requestSpec.getHeaders().add(HttpHeaderConstants.COOKIE, encodedCookie); }
/** * Renders health checks. * * @param ctx the request context */ @Override public void handle(Context ctx) throws Exception { ctx.getResponse().getHeaders() .add("Cache-Control", "no-cache, no-store, must-revalidate") .add("Pragma", "no-cache") .add("Expires", 0); String checkName = ctx.getPathTokens().get(name); if (checkName != null) { Optional<HealthCheck> first = ctx.first(HEALTH_CHECK_TYPE_TOKEN, healthCheck -> healthCheck.getName().equals(checkName) ? healthCheck : null); if (first.isPresent()) { ctx.render(HealthCheck.checkAll(ctx, Collections.singleton(first.get()))); } else { ctx.clientError(404); } } else { ctx.render(HealthCheck.checkAll(ctx, throttle, ctx.getAll(HEALTH_CHECK_TYPE_TOKEN))); } }
@Override public void handle(Context context) throws Exception { HttpMethod method = context.getRequest().getMethod(); if (method.isOptions() && !handlers.containsKey(HttpMethod.OPTIONS)) { List<String> parts = new ArrayList<>(Collections2.transform(handlers.keySet(), HttpMethod::getName)); Collections.sort(parts); String methods = JOINER.join(parts); context.getResponse().getHeaders().add(HttpHeaderConstants.ALLOW, methods); context.getResponse().status(200).send(); } else { Handler handler = handlers.get(method); if (handler != null) { context.insert(handler); return; } if (method.isHead()) { Handler getHandler = handlers.get(HttpMethod.GET); if (getHandler != null) { context.insert(getHandler); return; } } NO_METHOD_HANDLER.handle(context); } }
/** * {@inheritDoc} */ @Override public void render(Context context) throws Exception { Response response = context.getResponse(); response.getHeaders().add(HttpHeaderConstants.TRANSFER_ENCODING, HttpHeaderConstants.CHUNKED); response.getHeaders().set(HttpHeaderConstants.CONTENT_TYPE, getContentType()); Publisher<? extends ByteBuf> publisher = publisher(context.get(ByteBufAllocator.class)); response.sendStream(publisher); }
public void handle(Context context) { ratpack.http.HttpMethod requestMethod = context.getRequest().getMethod(); if (requestMethod == method || requestMethod.name(method.getName())) { context.next(); } else if (requestMethod.isOptions()) { Response response = context.getResponse(); response.getHeaders().add(HttpHeaderConstants.ALLOW, method); response.status(200).send(); } else { context.clientError(405); } } }