List of usage examples for io.netty.handler.codec.http HttpHeaders setDate
@Deprecated public static void setDate(HttpMessage message, Date value)
From source file:com.bloom.zerofs.rest.NettyResponseChannel.java
License:Open Source License
/** * Provided a cause, returns an error response with the right status and error message. * @param cause the cause of the error.//w w w .jav a 2 s . c o m * @return a {@link FullHttpResponse} with the error message that can be sent to the client. */ private FullHttpResponse getErrorResponse(Throwable cause) { HttpResponseStatus status; StringBuilder errReason = new StringBuilder(); if (cause instanceof RestServiceException) { RestServiceErrorCode restServiceErrorCode = ((RestServiceException) cause).getErrorCode(); errorResponseStatus = ResponseStatus.getResponseStatus(restServiceErrorCode); status = getHttpResponseStatus(errorResponseStatus); if (status == HttpResponseStatus.BAD_REQUEST) { errReason.append(" [").append(Utils.getRootCause(cause).getMessage()).append("]"); } } else { nettyMetrics.internalServerErrorCount.inc(); status = HttpResponseStatus.INTERNAL_SERVER_ERROR; errorResponseStatus = ResponseStatus.InternalServerError; } String fullMsg = "Failure: " + status + errReason; logger.trace("Constructed error response for the client - [{}]", fullMsg); FullHttpResponse response; if (request != null && !request.getRestMethod().equals(RestMethod.HEAD)) { response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status, Unpooled.wrappedBuffer(fullMsg.getBytes())); } else { // for HEAD, we cannot send the actual body but we need to return what the length would have been if this was GET. // https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html (Section 9.4) response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status); } HttpHeaders.setDate(response, new GregorianCalendar().getTime()); HttpHeaders.setContentLength(response, fullMsg.length()); HttpHeaders.setHeader(response, HttpHeaders.Names.CONTENT_TYPE, "text/plain; charset=UTF-8"); boolean keepAlive = !forceClose && HttpHeaders.isKeepAlive(responseMetadata) && request != null && !request.getRestMethod().equals(RestMethod.POST) && !CLOSE_CONNECTION_ERROR_STATUSES.contains(status); HttpHeaders.setKeepAlive(response, keepAlive); return response; }
From source file:com.github.ambry.rest.NettyResponseChannel.java
License:Open Source License
/** * Provided a cause, returns an error response with the right status and error message. * @param cause the cause of the error./* w ww. j a v a2 s. com*/ * @return a {@link FullHttpResponse} with the error message that can be sent to the client. */ private FullHttpResponse getErrorResponse(Throwable cause) { HttpResponseStatus status; StringBuilder errReason = new StringBuilder(); if (cause instanceof RestServiceException) { RestServiceErrorCode restServiceErrorCode = ((RestServiceException) cause).getErrorCode(); status = getHttpResponseStatus(ResponseStatus.getResponseStatus(restServiceErrorCode)); if (status == HttpResponseStatus.BAD_REQUEST) { errReason.append(" [").append(Utils.getRootCause(cause).getMessage()).append("]"); } } else { nettyMetrics.internalServerErrorCount.inc(); status = HttpResponseStatus.INTERNAL_SERVER_ERROR; } String fullMsg = "Failure: " + status + errReason; logger.trace("Constructed error response for the client - [{}]", fullMsg); FullHttpResponse response; if (request != null && !request.getRestMethod().equals(RestMethod.HEAD)) { response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status, Unpooled.wrappedBuffer(fullMsg.getBytes())); } else { // for HEAD, we cannot send the actual body but we need to return what the length would have been if this was GET. // https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html (Section 9.4) response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status); } HttpHeaders.setDate(response, new GregorianCalendar().getTime()); HttpHeaders.setContentLength(response, fullMsg.length()); HttpHeaders.setHeader(response, HttpHeaders.Names.CONTENT_TYPE, "text/plain; charset=UTF-8"); boolean keepAlive = request != null && !request.getRestMethod().equals(RestMethod.POST) && !CLOSE_CONNECTION_ERROR_STATUSES.contains(status); HttpHeaders.setKeepAlive(response, keepAlive); return response; }
From source file:io.reactivex.netty.protocol.http.client.HttpRequestHeaders.java
License:Apache License
public void setDate(Date value) { HttpHeaders.setDate(nettyRequest, value); }
From source file:io.reactivex.netty.protocol.http.server.HttpResponseHeaders.java
License:Apache License
public void setDate(Date value) { HttpHeaders.setDate(nettyResponse, value); }
From source file:reactor.io.net.impl.netty.http.NettyHttpResponseHeaders.java
License:Open Source License
@Override public ResponseHeaders date(Date value) { HttpHeaders.setDate(this.nettyResponse, value); return this; }
From source file:rxweb.engine.server.netty.NettyResponseHeadersAdapter.java
License:Apache License
@Override public ServerResponseHeaders date(Date value) { HttpHeaders.setDate(this.nettyResponse, value); return this; }