public void sendResponse() { int statusCode = context.getResponse().getStatus().getCode(); if (statusCode >= 400) { context.clientError(statusCode); } else { context.getResponse().send(MediaType.TEXT_HTML, responseContent); } }
public RatpackWebContext(Context ctx, TypedData body, SessionData session) { this.context = ctx; this.session = session; this.request = ctx.getRequest(); this.response = ctx.getResponse(); if (isFormAvailable(request, body)) { this.form = FormDecoder.parseForm(ctx, body, MultiValueMap.empty()); } else { this.form = new DefaultForm(MultiValueMap.empty(), MultiValueMap.empty()); } }
@Override public void handle(Context ctx, RPCConfig rpc) { ctx.get(HttpClient.class) .requestStream( rpc.getURI(), requestSpec -> { requestSpec.post(); requestSpec.body(body -> body.type(jsonType).text(buildStatusReq())); requestSpec.redirects(0); if (rpc.getUsername() != null) { requestSpec.basicAuth(rpc.getUsername(), rpc.getPassword()); } }) .then( responseStream -> { // TODO: Extract from JsonRpcResponse and return more restful JSON format (no RPC // wrapper) responseStream.forwardTo(ctx.getResponse()); }); }
public void redirect(Context context, String location, int code) { context.getResponse().status(code); String normalizedLocation = generateRedirectLocation(context, context.getRequest(), location); context.getResponse().getHeaders().set(HttpHeaderConstants.LOCATION, normalizedLocation); context.getResponse().send(); }
public void sendResponse(RequiresHttpAction action) { context.getResponse().status(action.getCode()); sendResponse(); }
@Override public void setResponseHeader(String name, String value) { context.getResponse().getHeaders().set(name, value); }
@Override public void setResponseStatus(int code) { context.getResponse().status(code); }