public static Response methodNotAllowed(final String methodName, final String... allowedMethods) { checkNotNull(methodName); checkNotNull(allowedMethods); checkArgument(allowedMethods.length != 0); return new Response.Builder() .status(Status.failure(METHOD_NOT_ALLOWED, methodName)) .header(HttpHeaders.ALLOW, Joiner.on(',').join(allowedMethods)) .build(); }
/** * Builds the challenge for authorization by setting a HTTP <code>401</code> (Unauthorized) status as well as the * response's <code>WWW-Authenticate</code> header. * <p/> * The header value constructed is equal to: * <p/> * <code>String.format("%s realm=\"%s\"", authenticationScheme, realmName)</code> * * @param message to be shown next to the status code * @param authenticationScheme authentication scheme used in the authentication challenge header * @param realmName realm name used in the authentication challenge header * @return a 401 authentication challenge response */ public static Response unauthorized(final String message, final String authenticationScheme, final String realmName) { checkNotNull(message); checkNotNull(authenticationScheme); checkNotNull(realmName); return new Response.Builder() .status(Status.failure(UNAUTHORIZED, message)) .header(HttpHeaders.WWW_AUTHENTICATE, String.format("%s realm=\"%s\"", authenticationScheme, realmName)) .build(); }
responseBuilder.header(HttpHeaders.ETAG, response.getHeaders().get(HttpHeaders.ETAG));
/** * Mutate the response into one that returns part of the payload. */ private Response partialResponse(final Response response, final Payload payload, final Range<Long> requestedRange) { Response.Builder builder = new Response.Builder() .copy(response) .status(Status.success(HttpStatus.PARTIAL_CONTENT)); Payload partialPayload = new PartialPayload(payload, requestedRange); builder.payload(partialPayload); // ResponseSender takes care of Content-Length header, via payload.size builder.header(HttpHeaders.CONTENT_RANGE, "bytes " + requestedRange.lowerEndpoint() + "-" + requestedRange.upperEndpoint() + "/" + payload.getSize()); return builder.build(); }