private void removeResponseBody(BaseMessage msg, MappingHttpResponse httpResponse) {
   // Populate all the common fields. These fields normally get populated in the outbound stage of
   // the parent handler but get skipped in this case due to
   // an empty message body
   httpResponse.setHeader(
       HttpHeaders.Names.DATE, DateFormatter.dateToHeaderFormattedString(new Date()));
   httpResponse.setHeader(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(0));
   if (msg.getCorrelationId() != null) {
     httpResponse.setHeader(ObjectStorageProperties.AMZ_REQUEST_ID, msg.getCorrelationId());
   }
   // Null the message body to remove it
   httpResponse.setMessage(null);
 }
  @Override
  public void outgoingMessage(ChannelHandlerContext ctx, MessageEvent event) throws Exception {
    if (event.getMessage() instanceof MappingHttpResponse) {
      MappingHttpResponse httpResponse = (MappingHttpResponse) event.getMessage();
      BaseMessage msg = (BaseMessage) httpResponse.getMessage();

      // Ordering if-else conditions from most to least restrictive i.e. narrow to broad filters
      if (msg instanceof PostObjectResponseType) {
        PostObjectResponseType postObjectResponse = (PostObjectResponseType) msg;
        String redirectUrl = postObjectResponse.getRedirectUrl();
        if (redirectUrl != null) {
          httpResponse.addHeader(HttpHeaders.Names.LOCATION, redirectUrl);
          httpResponse.setStatus(HttpResponseStatus.SEE_OTHER);
          httpResponse.setMessage(null);
        } else {
          Integer successCode = postObjectResponse.getSuccessCode();
          if (successCode != null) {
            if (successCode != 201) {
              httpResponse.setMessage(null);
              httpResponse.setStatus(new HttpResponseStatus(successCode, "OK"));
            } else {
              httpResponse.setStatus(new HttpResponseStatus(successCode, "Created"));
            }
          }
        }
        // have to force a close for browsers
        event.getFuture().addListener(ChannelFutureListener.CLOSE);
      } else if (msg instanceof CopyObjectResponseType) {
        CopyObjectResponseType copyResponse = (CopyObjectResponseType) msg;
        if (copyResponse.getVersionId() != null)
          httpResponse.addHeader("x-amz-version-id", copyResponse.getVersionId());
        if (copyResponse.getCopySourceVersionId() != null)
          httpResponse.addHeader(
              "x-amz-copy-source-version-id", copyResponse.getCopySourceVersionId());
      } else if (msg instanceof CreateBucketResponseType) {
        httpResponse.setStatus(HttpResponseStatus.OK);
        removeResponseBody(msg, httpResponse);
        event.getFuture().addListener(ChannelFutureListener.CLOSE);
      } else if (msg
          instanceof ObjectStorageDataResponseType) { // Filter for GETs and PUTs related to data
        ObjectStorageDataResponseType response = (ObjectStorageDataResponseType) msg;
        if (response.getEtag() != null) {
          httpResponse.setHeader(HttpHeaders.Names.ETAG, '\"' + response.getEtag() + '\"');
        }
        if (response.getVersionId() != null) {
          httpResponse.setHeader(ObjectStorageProperties.X_AMZ_VERSION_ID, response.getVersionId());
        }
        if (msg instanceof ObjectStorageDataGetResponseType && response.getLastModified() != null) {
          httpResponse.setHeader(
              HttpHeaders.Names.LAST_MODIFIED,
              DateFormatter.dateToHeaderFormattedString(response.getLastModified()));
        }
        // Remove the content in response for certain operations
        if (msg instanceof PutObjectResponseType || msg instanceof UploadPartResponseType) {
          removeResponseBody(msg, httpResponse);
        }
      } else if (msg
          instanceof ObjectStorageResponseType) { // Filter for GETs and PUTs *NOT* related to data
        // Remove the content in response for certain operations
        if (msg instanceof SetBucketAccessControlPolicyResponseType
            || msg instanceof SetBucketLifecycleResponseType
            || msg instanceof SetBucketLoggingStatusResponseType
            || msg instanceof SetBucketVersioningStatusResponseType
            || msg instanceof SetObjectAccessControlPolicyResponseType
            || msg instanceof SetBucketTaggingResponseType) {
          if (msg instanceof SetObjectAccessControlPolicyResponseType
              && ((SetObjectAccessControlPolicyResponseType) msg).getVersionId() != null) {
            httpResponse.setHeader(
                ObjectStorageProperties.X_AMZ_VERSION_ID,
                ((SetObjectAccessControlPolicyResponseType) msg).getVersionId());
          }

          // Moved the below logic to the actual operation in ObjectStorageGateway.java.
          /*// AWS returns in a 204, rather than a 200 like other requests for SetBucketTaggingResponseType
          if ( msg instanceof SetBucketTaggingResponseType ) {
          	httpResponse.setStatus( HttpResponseStatus.NO_CONTENT );
          }*/
          removeResponseBody(msg, httpResponse);
        }
      }
    }
  }