/**
   * Does the provided request form a valid web socket handshake request?
   *
   * @param request the candidate web socket handshake request
   * @return true iff the provided request is a web socket handshake request.
   */
  protected boolean doValidate(HttpRequestMessage request, final boolean isPostMethodAllowed) {

    if (!isPostMethodAllowed) {
      if (request.getMethod() != HttpMethod.GET) {
        return false;
      }
    } else {
      if (request.getMethod() != HttpMethod.GET || request.getMethod() == HttpMethod.POST) {
        return false;
      }
    }

    if (request.getVersion() != HttpVersion.HTTP_1_1) {
      return false;
    }

    if (request.getRequestURI() == null) {
      return false;
    }

    boolean ok = requireHeader(request, "Connection", "Upgrade");
    if (!ok) {
      return false;
    }

    ok = requireHeader(request, "Upgrade", "WebSocket");
    if (!ok) {
      return false;
    }

    ok = requireHeader(request, "Host");

    return ok;
  }
 private void oneOfIsEmulatedWebSocketRequest(
     Expectations exp, HttpRequestMessage expectedRequest) {
   exp.allowing(serverSession).getRequestURI();
   exp.will(returnValue(expectedRequest.getRequestURI()));
 }