Builder addHttpStatus(String text) { final HttpStatus s = HttpStatus.valueOf(Integer.valueOf(text)); statusSet.add(s); isEmpty = false; return this; }
/** * Creates a new HTTP response. * * @param statusCode the HTTP status code */ static AggregatedHttpMessage of(int statusCode) { return of(HttpStatus.valueOf(statusCode)); }
/** * Returns a new {@link HttpResponseException} instance with the specified HTTP status code. */ public static HttpResponseException of(int statusCode) { return of(HttpStatus.valueOf(statusCode)); }
/** * Returns new HTTP response headers. */ static HttpHeaders of(int statusCode) { return of(HttpStatus.valueOf(statusCode)); }
/** * Writes the HTTP response of the specified {@code statusCode} and closes the stream if the * {@link HttpStatusClass} is not {@linkplain HttpStatusClass#INFORMATIONAL informational} (1xx). * * @deprecated Use {@link HttpResponse#of(int)}. */ @Deprecated default void respond(int statusCode) { respond(HttpStatus.valueOf(statusCode)); }
/** * Creates a new HTTP response of the specified {@code statusCode} and closes the stream if the * {@link HttpStatusClass} is not {@linkplain HttpStatusClass#INFORMATIONAL informational} (1xx). */ static HttpResponse of(int statusCode) { return of(HttpStatus.valueOf(statusCode)); }
@Nullable @Override public HttpStatus status() { final HttpStatus status = this.status; if (status != null) { return status; } final String statusStr = get(HttpHeaderNames.STATUS); if (statusStr == null) { return null; } try { return this.status = HttpStatus.valueOf(Integer.valueOf(statusStr)); } catch (NumberFormatException ignored) { throw new IllegalStateException("invalid status: " + statusStr); } }
@Override public HttpHeaders status(int statusCode) { final HttpStatus status = this.status = HttpStatus.valueOf(statusCode); set(HttpHeaderNames.STATUS, status.codeAsText()); return this; }
/** * Returns a new {@link HttpStatusException} instance with the specified HTTP status code. */ public static HttpStatusException of(int statusCode) { if (statusCode < 0 || statusCode >= 1000) { final HttpStatus status = HttpStatus.valueOf(statusCode); if (Flags.verboseExceptions()) { return new HttpStatusException(status); } else { return new HttpStatusException(status, false); } } else { return EXCEPTIONS[statusCode]; } }
checkArgument(statusCode >= 0, "invalid HTTP status code: %s (expected: >= 0)", statusCode); return HttpStatus.valueOf(statusCode); }); final HttpHeaders defaultHeaders = HttpHeaders.of(defaultResponseStatus(defaultResponseStatus, method));
private static HttpHeaders toResponseHeaders(ArmeriaHttpTransport transport) { final MetaData.Response info = transport.info; if (info == null) { throw new IllegalStateException("response metadata unavailable"); } final HttpHeaders headers = HttpHeaders.of(HttpStatus.valueOf(info.getStatus())); info.getFields().forEach(e -> headers.add(HttpHeaderNames.of(e.getName()), e.getValue())); if (transport.method != HttpMethod.HEAD) { headers.setLong(HttpHeaderNames.CONTENT_LENGTH, transport.contentLength); } return headers; }
private static HttpHeaders convertResponse(Response coyoteRes) { final HttpHeaders headers = HttpHeaders.of(HttpStatus.valueOf(coyoteRes.getStatus())); final String contentType = coyoteRes.getContentType(); if (contentType != null && !contentType.isEmpty()) { headers.set(HttpHeaderNames.CONTENT_TYPE, contentType); } final long contentLength = coyoteRes.getBytesWritten(true); // 'true' will trigger flush. final String method = coyoteRes.getRequest().method().toString(); if (!"HEAD".equals(method)) { headers.setLong(HttpHeaderNames.CONTENT_LENGTH, contentLength); } final MimeHeaders cHeaders = coyoteRes.getMimeHeaders(); final int numHeaders = cHeaders.size(); for (int i = 0; i < numHeaders; i++) { final AsciiString name = toHeaderName(cHeaders.getName(i)); if (name == null) { continue; } final String value = toHeaderValue(cHeaders.getValue(i)); if (value == null) { continue; } headers.add(name.toLowerCase(), value); } return headers; }