private void validateState(HttpContent httpContent) throws RestServiceException {
    long bytesReceivedTillNow = bytesReceived.addAndGet(httpContent.content().readableBytes());
    if (size > 0) {
      if (bytesReceivedTillNow > size) {
        channelException = new RestServiceException("Size of content is more than the size provided in headers",
            RestServiceErrorCode.BadRequest);
        throw (RestServiceException) channelException;
      } else if (httpContent instanceof LastHttpContent && bytesReceivedTillNow != size) {
        channelException = new RestServiceException("Size of content is less than the size provided in headers",
            RestServiceErrorCode.BadRequest);
        throw (RestServiceException) channelException;
      }
    }
  }
Validates the stream by checking that the size in the headers matches the size of the actual data.
@param httpContent the {@link HttpContent} that was just received.
@throws RestServiceException if {@code httpContent} is the last piece of content and the size of data does
                             not match the size in the header.
ambry-rest/src/main/java/com/github/ambry/rest/NettyRequest.java