當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpStatus.code方法代碼示例

本文整理匯總了Java中com.linecorp.armeria.common.HttpStatus.code方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpStatus.code方法的具體用法?Java HttpStatus.code怎麽用?Java HttpStatus.code使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.linecorp.armeria.common.HttpStatus的用法示例。


在下文中一共展示了HttpStatus.code方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: respond

import com.linecorp.armeria.common.HttpStatus; //導入方法依賴的package包/類
private void respond(ChannelHandlerContext ctx, DecodedHttpRequest req, HttpStatus status,
                     RequestContext reqCtx, @Nullable Throwable cause) {

    if (status.code() < 400) {
        respond(ctx, req, AggregatedHttpMessage.of(HttpHeaders.of(status)), reqCtx, cause);
        return;
    }

    final HttpData content;
    if (req.method() == HttpMethod.HEAD || ArmeriaHttpUtil.isContentAlwaysEmpty(status)) {
        content = HttpData.EMPTY_DATA;
    } else {
        content = status.toHttpData();
    }

    respond(ctx, req,
            AggregatedHttpMessage.of(
                    HttpHeaders.of(status)
                               .contentType(ERROR_CONTENT_TYPE),
                    content), reqCtx, cause);
}
 
開發者ID:line,項目名稱:armeria,代碼行數:22,代碼來源:HttpServerHandler.java

示例2: of

import com.linecorp.armeria.common.HttpStatus; //導入方法依賴的package包/類
/**
 * Returns a new {@link HttpStatusException} instance with the specified {@link HttpStatus}.
 */
public static HttpStatusException of(HttpStatus httpStatus) {
    requireNonNull(httpStatus, "httpStatus");
    if (Flags.verboseExceptions()) {
        return new HttpStatusException(httpStatus);
    } else {
        final int statusCode = httpStatus.code();
        return EXCEPTIONS.computeIfAbsent(statusCode, code ->
                Exceptions.clearTrace(new HttpStatusException(HttpStatus.valueOf(code))));
    }
}
 
開發者ID:line,項目名稱:armeria,代碼行數:14,代碼來源:HttpStatusException.java

示例3: isContentAlwaysEmpty

import com.linecorp.armeria.common.HttpStatus; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:line,項目名稱:armeria,代碼行數:17,代碼來源:ArmeriaHttpUtil.java

示例4: onNext

import com.linecorp.armeria.common.HttpStatus; //導入方法依賴的package包/類
@Override
public void onNext(HttpObject o) {
    if (!(o instanceof HttpData) && !(o instanceof HttpHeaders)) {
        throw newIllegalStateException(
                "published an HttpObject that's neither HttpHeaders nor HttpData: " + o +
                " (service: " + service() + ')');
    }

    boolean endOfStream = o.isEndOfStream();
    switch (state) {
        case NEEDS_HEADERS: {
            logBuilder().startResponse();
            if (!(o instanceof HttpHeaders)) {
                throw newIllegalStateException(
                        "published an HttpData without a preceding Http2Headers: " + o +
                        " (service: " + service() + ')');
            }

            final HttpHeaders headers = (HttpHeaders) o;
            final HttpStatus status = headers.status();
            if (status == null) {
                throw newIllegalStateException("published an HttpHeaders without status: " + o +
                                               " (service: " + service() + ')');
            }

            if (status.codeClass() == HttpStatusClass.INFORMATIONAL) {
                // Needs non-informational headers.
                break;
            }

            final int statusCode = status.code();
            logBuilder().responseHeaders(headers);

            if (req.method() == HttpMethod.HEAD) {
                // HEAD responses always close the stream with the initial headers, even if not explicitly
                // set.
                endOfStream = true;
                break;
            }

            switch (statusCode) {
                case 204:
                case 205:
                case 304:
                    // These responses are not allowed to have content so we always close the stream even if
                    // not explicitly set.
                    endOfStream = true;
                    break;
                default:
                    state = State.NEEDS_DATA_OR_TRAILING_HEADERS;
            }
            break;
        }
        case NEEDS_DATA_OR_TRAILING_HEADERS: {
            if (o instanceof HttpHeaders) {
                final HttpHeaders trailingHeaders = (HttpHeaders) o;
                if (trailingHeaders.status() != null) {
                    throw newIllegalStateException(
                            "published a trailing HttpHeaders with status: " + o +
                            " (service: " + service() + ')');
                }

                // Trailing headers always end the stream even if not explicitly set.
                endOfStream = true;
            }
            break;
        }
        case DONE:
            ReferenceCountUtil.safeRelease(o);
            return;
    }

    write(o, endOfStream, true);
}
 
開發者ID:line,項目名稱:armeria,代碼行數:75,代碼來源:HttpResponseSubscriber.java

示例5: statusCode

import com.linecorp.armeria.common.HttpStatus; //導入方法依賴的package包/類
/**
 * Returns the status code of the {@link Response}.
 *
 * @return the integer value of the {@link #status()}.
 *         {@code -1} if {@link #status()} returns {@code null}.
 */
default int statusCode() {
    final HttpStatus status = status();
    return status != null ? status.code() : -1;
}
 
開發者ID:line,項目名稱:armeria,代碼行數:11,代碼來源:RequestLog.java


注:本文中的com.linecorp.armeria.common.HttpStatus.code方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。