public static HttpResponse createRejection(HttpRequest request, String reason) {
   HttpVersion version = request != null ? request.getProtocolVersion() : HttpVersion.HTTP_1_1;
   HttpResponse response = new DefaultHttpResponse(version, HttpResponseStatus.BAD_REQUEST);
   response.setHeader(HttpHeaders.Names.CONTENT_TYPE, "text/plain; charset=\"utf-8\"");
   ChannelBuffer reasonBuffer = ChannelBuffers.wrappedBuffer(toBytes(reason));
   response.setHeader(
       HttpHeaders.Names.CONTENT_LENGTH, Integer.toString(reasonBuffer.readableBytes()));
   response.setContent(reasonBuffer);
   return response;
 }
 private static HttpResponse createResponseTemplate(
     HttpResponseStatus status, ChannelBuffer data) {
   HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, status);
   if (data != null) {
     response.setHeader(HttpHeaders.Names.CONTENT_LENGTH, Integer.toString(data.readableBytes()));
     response.setHeader(HttpHeaders.Names.CONTENT_TYPE, "application/octet-stream");
     response.setContent(data);
   } else {
     response.setHeader(HttpHeaders.Names.CONTENT_LENGTH, "0");
     response.setContent(null);
   }
   return response;
 }
 public static HttpResponse createTunnelOpenResponse(String tunnelId) {
   HttpResponse response = createResponseTemplate(HttpResponseStatus.CREATED, null);
   response.setHeader(HttpHeaders.Names.SET_COOKIE, tunnelId);
   return response;
 }