public HTTPClient(string url, string destinationPath,
                   bool allowResume = true, HTTPHeaderList headers = null) :
     this(new HTTPRequest(url, headers))
 {
     _responseHandler = new HTTPResponseDownloadHandler(destinationPath,
                                                        allowResume);
 }
 public HTTPClient(HTTPRequest request = null,
                   HTTPResponseHandler responseHandler = null)
 {
     _connectionID      = Bindings.INVALID_CONNECTION_ID;
     _state             = ConnectionState.Initialized;
     _connectionTimeout = DefaultConnectionTimeout;
     _error             = null;
     _requestSent       = false;
     _request           = request;
     _response          = null;
     _responseHandler   = responseHandler;
 }
        protected bool SanityCheckStart()
        {
            string description = null;

            Error.KnownCode code = Error.KnownCode.ExtendedErrorMin;

            if (_disposed == true)
            {
                description = "Client is already disposed";
                code        = Error.KnownCode.ClientAlreadyDisposedError;
            }
            else if (_request == null)
            {
                description = "Request is not set";
                code        = Error.KnownCode.RequestNotSetError;
            }
            else if (_request.url == null)
            {
                description = "Request URL is invalid or not set";
                code        = Error.KnownCode.RequestURLInvalid;
            }
            else
            {
                if ((_request.contentHandler != null) &&
                    (_request.contentHandler.OnWillStart(this) == false))
                {
                    description = "Request handler refused to start";
                    code        = Error.KnownCode.RequestHandlerDidNotStart;
                }
                else
                {
                    if (_responseHandler == null)
                    {
                        _responseHandler = new HTTPResponseMemoryStreamHandler();
                    }

                    if (_responseHandler.OnWillStart(this) == false)
                    {
                        description = "Response handler refused to start";
                        code        = Error.KnownCode.ResponseHandlerDidNotStart;
                    }
                }
            }

            if (description == null)
            {
                return(true);
            }

            _error = new Error(Bindings.ERROR_DOMAIN, (long)code, description);
            return(false);
        }
Example #4
0
    protected bool SanityCheckStart()
    {
      string description = null;
      Error.KnownCode code = Error.KnownCode.ExtendedErrorMin;

      if (_disposed == true)
      {
        description = "Client is already disposed";
        code = Error.KnownCode.ClientAlreadyDisposedError;
      }
      else if (_request == null)
      {
        description = "Request is not set";
        code = Error.KnownCode.RequestNotSetError;
      }
      else if (_request.url == null)
      {
        description = "Request URL is invalid or not set";
        code = Error.KnownCode.RequestURLInvalid;
      }
      else
      {
        if ((_request.contentHandler != null) &&
            (_request.contentHandler.OnWillStart(this) == false))
        {
          description = "Request handler refused to start";
          code = Error.KnownCode.RequestHandlerDidNotStart;
        }
        else
        {
          if (_responseHandler == null)
          {
            _responseHandler = new HTTPResponseMemoryStreamHandler();
          }

          if (_responseHandler.OnWillStart(this) == false)
          {
            description = "Response handler refused to start";
            code = Error.KnownCode.ResponseHandlerDidNotStart;
          }
        }
      }

      if (description == null)
      {
        return true;
      }

      _error = new Error(Bindings.ERROR_DOMAIN, (long)code, description);
      return false;
    }
Example #5
0
 public HTTPClient SetResponseHandler(HTTPResponseHandler handler)
 {
   _responseHandler = handler;
   return this;
 }
Example #6
0
 public HTTPClient(string url, string destinationPath,
     bool allowResume = true, HTTPHeaderList headers = null) :
   this(new HTTPRequest(url, headers))
 {
   _responseHandler = new HTTPResponseDownloadHandler(destinationPath,
       allowResume);
 }
Example #7
0
 public HTTPClient(HTTPRequest request = null,
     HTTPResponseHandler responseHandler = null)
 {
   _connectionID = Bindings.INVALID_CONNECTION_ID;
   _state = ConnectionState.Initialized;
   _connectionTimeout = DefaultConnectionTimeout;
   _error = null;
   _requestSent = false;
   _request = request;
   _response = null;
   _responseHandler = responseHandler;
 }
 public HTTPClient SetResponseHandler(HTTPResponseHandler handler)
 {
     _responseHandler = handler;
     return(this);
 }