Пример #1
0
    // As client
    private HttpResponse sendHttpRequest (HttpRequest request, int millisecondsTimeout)
    {
      _logger.Debug ("A request to the server:\n" + request.ToString ());
      var res = request.GetResponse (_stream, millisecondsTimeout);
      _logger.Debug ("A response to this request:\n" + res.ToString ());

      return res;
    }
Пример #2
0
    internal static HttpRequest CreateConnectRequest (Uri uri)
    {
      var host = uri.DnsSafeHost;
      var port = uri.Port;
      var authority = String.Format ("{0}:{1}", host, port);
      var req = new HttpRequest ("CONNECT", authority);
      req.Headers["Host"] = port == 80 ? host : authority;

      return req;
    }
Пример #3
0
    internal static HttpRequest CreateWebSocketRequest (Uri uri)
    {
      var req = new HttpRequest ("GET", uri.PathAndQuery);

      var headers = req.Headers;
      headers["Upgrade"] = "websocket";
      headers["Connection"] = "Upgrade";
      headers["Host"] = uri.Port == 80 ? uri.DnsSafeHost : uri.Authority;

      return req;
    }
    internal static HttpRequest CreateWebSocketRequest (Uri uri)
    {
      var req = new HttpRequest ("GET", uri.PathAndQuery);
      var headers = req.Headers;

      // Only includes a port number in the Host header value if it's non-default.
      // See: https://tools.ietf.org/html/rfc6455#page-17
      var port = uri.Port;
      var schm = uri.Scheme;
      headers["Host"] = (port == 80 && schm == "ws") || (port == 443 && schm == "wss")
                        ? uri.DnsSafeHost
                        : uri.Authority;

      headers["Upgrade"] = "websocket";
      headers["Connection"] = "Upgrade";

      return req;
    }