/** * Returns the {@link CircuitBreakerStrategy} that determines a {@link Response} as successful * when its {@link HttpStatus} is not {@link HttpStatusClass#SERVER_ERROR} and there was no * {@link Exception} raised. */ static CircuitBreakerStrategy onServerErrorStatus() { return onStatus( (status, thrown) -> status != null && status.codeClass() != HttpStatusClass.SERVER_ERROR); }
/** * Returns the {@link RetryStrategy} that retries the request with the specified {@code backoff} * when the response status matches {@link HttpStatusClass#SERVER_ERROR} or an {@link Exception} is raised. */ static RetryStrategy onServerErrorStatus(Backoff backoff) { requireNonNull(backoff, "backoff"); return onStatus((status, thrown) -> { if (thrown != null || (status != null && status.codeClass() == HttpStatusClass.SERVER_ERROR)) { return backoff; } return null; }); }
/** * Returns {@code true} if the content of the response with the given {@link HttpStatus} is expected to * be always empty (1xx, 204, 205 and 304 responses.) */ public static boolean isContentAlwaysEmpty(HttpStatus status) { if (status.codeClass() == HttpStatusClass.INFORMATIONAL) { return true; } switch (status.code()) { case 204: case 205: case 304: return true; } return false; }
@Override public void onNext(HttpObject httpObject) { if (publisher != null) { publisher.relayOnNext(httpObject); return; } if (httpObject instanceof HttpHeaders) { final HttpHeaders headers = (HttpHeaders) httpObject; final HttpStatus status = headers.status(); if (status != null && status.codeClass() != HttpStatusClass.INFORMATIONAL) { future.complete(headers); return; } } if (!future.isDone()) { ensureSubscribed().request(1); } }
@Override public void onNext(HttpObject o) { if (o instanceof HttpHeaders) { final HttpHeaders headers = (HttpHeaders) o; final HttpStatus status = headers.status(); if (status != null && status.codeClass() != HttpStatusClass.INFORMATIONAL && this.headers == null) { this.headers = headers; assert subscription != null; subscription.cancel(); } } }
@Override protected HttpObject filter(HttpObject obj) { if (!(obj instanceof HttpHeaders)) { return obj; } final HttpHeaders headers = (HttpHeaders) obj; final HttpStatus status = headers.status(); if (status == null || status.codeClass() == HttpStatusClass.INFORMATIONAL) { return headers; } final HttpHeaders mutableHeaders = headers.toMutable(); setCorsResponseHeaders(ctx, req, mutableHeaders); return mutableHeaders.asImmutable(); } };
case WAIT_NON_INFORMATIONAL: final HttpStatus status = headers.status(); if (status != null && status.codeClass() != HttpStatusClass.INFORMATIONAL) { state = State.WAIT_CONTENT;
/** * Writes the HTTP response of the specified {@link HttpStatus} and closes the stream if the * {@link HttpStatusClass} is not {@linkplain HttpStatusClass#INFORMATIONAL informational} (1xx). * * @deprecated Use {@link HttpResponse#of(HttpStatus)}. */ @Deprecated default void respond(HttpStatus status) { requireNonNull(status, "status"); if (status.codeClass() == HttpStatusClass.INFORMATIONAL) { write(HttpHeaders.of(status)); } else if (isContentAlwaysEmpty(status)) { write(HttpHeaders.of(status)); close(); } else { respond(status, MediaType.PLAIN_TEXT_UTF_8, status.toHttpData()); } }
if (status != null && status.codeClass() == HttpStatusClass.INFORMATIONAL) { return obj;
/** * Creates a new HTTP response of the specified {@link HttpStatus} and closes the stream if the * {@link HttpStatusClass} is not {@linkplain HttpStatusClass#INFORMATIONAL informational} (1xx). */ static HttpResponse of(HttpStatus status) { requireNonNull(status, "status"); if (status.codeClass() == HttpStatusClass.INFORMATIONAL) { final HttpResponseWriter res = streaming(); res.write(HttpHeaders.of(status)); return res; } else if (isContentAlwaysEmpty(status)) { return new OneElementFixedHttpResponse(HttpHeaders.of(status)); } else { return of(status, MediaType.PLAIN_TEXT_UTF_8, status.toHttpData()); } }
@Override public boolean tryWrite(HttpObject o) { if (o instanceof HttpHeaders) { // NB: It's safe to call logBuilder.start() multiple times. logBuilder.startResponse(); final HttpHeaders headers = (HttpHeaders) o; final HttpStatus status = headers.status(); if (status != null && status.codeClass() != HttpStatusClass.INFORMATIONAL) { logBuilder.responseHeaders(headers); } } else if (o instanceof HttpData) { logBuilder.increaseResponseLength(((HttpData) o).length()); } return delegate.tryWrite(o); }
private ChannelFuture writeServerHeaders( int id, int streamId, HttpHeaders headers, boolean endStream) throws Http2Exception { final HttpObject converted = convertServerHeaders(streamId, headers, endStream); final HttpStatus status = headers.status(); if (status == null) { // Trailing headers final ChannelFuture f = write(id, converted, endStream); ch.flush(); return f; } if (status.codeClass() == HttpStatusClass.INFORMATIONAL) { // Informational status headers. final ChannelFuture f = write(id, converted, false); if (endStream) { // Can't end a stream with informational status in HTTP/1. f.addListener(ChannelFutureListener.CLOSE); } ch.flush(); return f; } // Non-informational status headers. return writeNonInformationalHeaders(id, converted, endStream); }
if (status != null && status.codeClass() == HttpStatusClass.INFORMATIONAL) { return obj;
if (!nonInformationalHeadersStarted) { // If not received a non-informational header yet if (status == null || status.codeClass() == HttpStatusClass.INFORMATIONAL) { return;
final boolean informational = status.codeClass() == HttpStatusClass.INFORMATIONAL; final HttpResponseStatus nettyStatus = HttpResponseStatus.valueOf(status.code());
if (status.codeClass() == HttpStatusClass.INFORMATIONAL) {
if (status.codeClass() == HttpStatusClass.INFORMATIONAL) {
if (status.codeClass() == HttpStatusClass.INFORMATIONAL) {