throw new HttpException("Cannot access static resource!", Http.Status.INTERNAL_SERVER_ERROR_500, e); } catch (HttpException httpException) { if (httpException.status().code() == Http.Status.NOT_FOUND_404.code()) {
res.status(Http.ResponseStatus.create(context.getStatus(), context.getStatusInfo().getReasonPhrase()));
res.status(Http.ResponseStatus.create(context.getStatus(), context.getStatusInfo().getReasonPhrase()));
switch (res.status().family()) { case INFORMATIONAL: case SUCCESSFUL: .addParam(plain("method", req.method())) .addParam(plain("path", req.path())) .addParam(plain("status", String.valueOf(res.status().code()))) .addParam(plain("subject", securityContext.getUser().orElse(SecurityContext.ANONYMOUS))) .addParam(plain("transport", "http"))
DefaultHttpResponse response = new DefaultHttpResponse(HTTP_1_1, valueOf(status.code())); for (Map.Entry<String, List<String>> headerEntry : headers.entrySet()) { response.headers().add(headerEntry.getKey(), headerEntry.getValue()); if (status.code() != Http.Status.NO_CONTENT_204.code()) { HttpUtil.setTransferEncodingChunked(response, true);
switch (res.status().family()) { case INFORMATIONAL: case SUCCESSFUL: .addParam(plain("method", req.method())) .addParam(plain("path", req.path())) .addParam(plain("status", String.valueOf(res.status().code()))) .addParam(plain("subject", securityContext.user().orElse(SecurityContext.ANONYMOUS))) .addParam(plain("transport", "http"))
Http.ResponseStatus httpStatus = response.status(); if (httpStatus != null) { int statusCode = httpStatus.code(); Tags.HTTP_STATUS.set(span, statusCode); if (statusCode >= 400) {
DefaultHttpResponse response = new DefaultHttpResponse(HTTP_1_1, valueOf(status.code())); for (Map.Entry<String, List<String>> headerEntry : headers.entrySet()) { response.headers().add(headerEntry.getKey(), headerEntry.getValue()); if (status.code() != Http.Status.NO_CONTENT_204.code()) { HttpUtil.setTransferEncodingChunked(response, true);
/** * Specific status codes requires or omits specific headers. * * @param data mutable headers data * @param status response status code * @return filtered headers */ private Map<String, List<String>> filterSpecificHeaders(Map<String, List<String>> data, Http.ResponseStatus status) { if (data == null) { return null; } if (status.code() == Http.Status.NO_CONTENT_204.code()) { data.remove(Http.Header.TRANSFER_ENCODING); data.remove(Http.Header.CONTENT_DISPOSITION); data.remove(Http.Header.CONTENT_ENCODING); data.remove(Http.Header.CONTENT_LANGUAGE); data.remove(Http.Header.CONTENT_LENGTH); data.remove(Http.Header.CONTENT_LOCATION); data.remove(Http.Header.CONTENT_RANGE); data.remove(Http.Header.CONTENT_TYPE); } return data; } }
/** * Convert a numerical status code into the corresponding ResponseStatus. * <p> * As opposed to {@link Status#find(int)}, this method is guaranteed to always return an instance. * For an unknown {@link Status} it creates an ad-hoc {@link ResponseStatus}. * * @param statusCode the numerical status code * @return the matching ResponseStatus; either a {@link Status} or an ad-hoc {@link ResponseStatus} */ static ResponseStatus create(int statusCode) { return create(statusCode, null); }
/** * Sets new HTTP status code. Can be done before headers are completed - see {@link ResponseHeaders} documentation. * * @param statusCode new status code * @throws AlreadyCompletedException if headers were completed (sent to the client) * @return this instance of {@link ServerResponse} */ default ServerResponse status(int statusCode) throws AlreadyCompletedException { return status(Http.ResponseStatus.create(statusCode)); }