public UpgradeConnection(EndPoint endp, Executor executor, DefaultWebSocketClient client) {
    super(endp, executor);
    this.client = client;
    this.bufferPool = client.getFactory().getBufferPool();
    this.parser = new HttpResponseHeaderParser();

    try {
      this.request = client.getUpgradeRequest();
    } catch (ClassCastException e) {
      client.failed(new RuntimeException("Invalid Upgrade Request structure", e));
    }
  }
 /**
  * Read / Parse the waiting read/fill buffer
  *
  * @param buffer the buffer to fill into from the endpoint
  * @return true if there is more to read, false if reading should stop
  */
 private boolean read(ByteBuffer buffer) {
   EndPoint endPoint = getEndPoint();
   try {
     while (true) {
       int filled = endPoint.fill(buffer);
       if (filled == 0) {
         return true;
       } else if (filled < 0) {
         LOG.debug("read - EOF Reached");
         return false;
       } else {
         if (LOG.isDebugEnabled()) {
           LOG.debug("Filled {} bytes - {}", filled, BufferUtil.toDetailString(buffer));
         }
         ClientUpgradeResponse resp = parser.parse(buffer);
         if (resp != null) {
           // Got a response!
           client.setUpgradeResponse(resp);
           validateResponse(resp);
           notifyConnect(resp);
           upgradeConnection(resp);
           return false; // do no more reading
         }
       }
     }
   } catch (IOException e) {
     LOG.warn(e);
     client.failed(e);
     disconnect(false);
     return false;
   } catch (UpgradeException e) {
     LOG.warn(e);
     client.failed(e);
     disconnect(false);
     return false;
   }
 }