index.js
function open() {
    var what
      , slice = true
      , requests = this
      , socket = requests.socket;

    requests.on('stream', function stream(data) {
      if (!slice) {
        return requests.emit('data', data);
      }

      //
      // Please note that we need to use a method here that works on both string
      // as well as ArrayBuffer's as we have no certainty that we're receiving
      // text.
      //
      var chunk = data.slice(requests.offset);
      requests.offset = data.length;

      requests.emit('data', chunk);
    });

    requests.on('end', function cleanup() {
      delete Requests.active[requests.id];
    });

    if (this.timeout) {
      socket.timeout = +this.timeout;
    }

    if ('cors' === this.mode.toLowerCase() && 'withCredentials' in socket) {
      socket.withCredentials = true;
    }

    //
    // ActiveXObject will throw an `Type Mismatch` exception when setting the to
    // an null-value and to be consistent with all XHR implementations we're going
    // to cast the value to a string.
    //
    // While we don't technically support the XDomainRequest of IE, we do want to
    // double check that the setRequestHeader is available before adding headers.
    //
    // Chrome has a bug where it will actually append values to the header instead
    // of overriding it. So if you do a double setRequestHeader(Content-Type) with
    // text/plain and with text/plain again, it will end up as `text/plain,
    // text/plain` as header value. This is why use a headers object as it
    // already eliminates duplicate headers.
    //
    for (what in this.headers) {
      if (this.headers[what] !== undefined && this.socket.setRequestHeader) {
        this.socket.setRequestHeader(what, this.headers[what] +'');
      }
    }

    //
    // Set the correct responseType method.
    //
    if (requests.streaming) {
      if (!this.body || 'string' === typeof this.body) {
        if ('multipart' in socket) {
          socket.multipart = true;
          slice = false;
        } else if (Requests.type.mozchunkedtext) {
          socket.responseType = 'moz-chunked-text';
          slice = false;
        }
      } else {
        if (Requests.type.mozchunkedarraybuffer) {
          socket.responseType = 'moz-chunked-arraybuffer';
        } else if (Requests.type.msstream) {
          socket.responseType = 'ms-stream';
        }
      }
    }

    listeners(socket, requests, requests.streaming);
    requests.emit('before', socket);

    send(socket, this.body, hang(function send(err) {
      if (err) {
        requests.emit('error', err);
        requests.emit('end', err);
      }

      requests.emit('send');
    }));
  }
function open() {
    var what
      , slice = true
      , requests = this
      , socket = requests.socket;

    requests.on('stream', function stream(data) {
      if (!slice) {
        return requests.emit('data', data);
      }

      //
      // Please note that we need to use a method here that works on both string
      // as well as ArrayBuffer's as we have no certainty that we're receiving
      // text.
      //
      var chunk = data.slice(requests.offset);
      requests.offset = data.length;

      requests.emit('data', chunk);
    });

    requests.on('end', function cleanup() {
      delete Requests.active[requests.id];
    });

    if (this.timeout) {
      socket.timeout = +this.timeout;
    }

    if ('cors' === this.mode.toLowerCase() && 'withCredentials' in socket) {
      socket.withCredentials = true;
    }

    //
    // ActiveXObject will throw an `Type Mismatch` exception when setting the to
    // an null-value and to be consistent with all XHR implementations we're going
    // to cast the value to a string.
    //
    // While we don't technically support the XDomainRequest of IE, we do want to
    // double check that the setRequestHeader is available before adding headers.
    //
    // Chrome has a bug where it will actually append values to the header instead
    // of overriding it. So if you do a double setRequestHeader(Content-Type) with
    // text/plain and with text/plain again, it will end up as `text/plain,
    // text/plain` as header value. This is why use a headers object as it
    // already eliminates duplicate headers.
    //
    for (what in this.headers) {
      if (this.headers[what] !== undefined && this.socket.setRequestHeader) {
        this.socket.setRequestHeader(what, this.headers[what] +'');
      }
    }

    //
    // Set the correct responseType method.
    //
    if (requests.streaming) {
      if (!this.body || 'string' === typeof this.body) {
        if ('multipart' in socket) {
          socket.multipart = true;
          slice = false;
        } else if (Requests.type.mozchunkedtext) {
          socket.responseType = 'moz-chunked-text';
          slice = false;
        }
      } else {
        if (Requests.type.mozchunkedarraybuffer) {
          socket.responseType = 'moz-chunked-arraybuffer';
        } else if (Requests.type.msstream) {
          socket.responseType = 'ms-stream';
        }
      }
    }

    listeners(socket, requests, requests.streaming);
    requests.emit('before', socket);

    send(socket, this.body, hang(function send(err) {
      if (err) {
        requests.emit('error', err);
        requests.emit('end', err);
      }

      requests.emit('send');
    }));
  }
function open ( ) { var what , slice = true , requests = this , socket = requests . socket ; requests . on ( 'stream' , function stream ( data ) { if ( ! slice ) { return requests . emit ( 'data' , data ) ; } // // Please note that we need to use a method here that works on both string // as well as ArrayBuffer's as we have no certainty that we're receiving // text. // var chunk = data . slice ( requests . offset ) ; requests . offset = data . length ; requests . emit ( 'data' , chunk ) ; } ) ; requests . on ( 'end' , function cleanup ( ) { delete Requests . active [ requests . id ] ; } ) ; if ( this . timeout ) { socket . timeout = + this . timeout ; } if ( 'cors' === this . mode . toLowerCase ( ) && 'withCredentials' in socket ) { socket . withCredentials = true ; } // // ActiveXObject will throw an `Type Mismatch` exception when setting the to // an null-value and to be consistent with all XHR implementations we're going // to cast the value to a string. // // While we don't technically support the XDomainRequest of IE, we do want to // double check that the setRequestHeader is available before adding headers. // // Chrome has a bug where it will actually append values to the header instead // of overriding it. So if you do a double setRequestHeader(Content-Type) with // text/plain and with text/plain again, it will end up as `text/plain, // text/plain` as header value. This is why use a headers object as it // already eliminates duplicate headers. // for ( what in this . headers ) { if ( this . headers [ what ] !== undefined && this . socket . setRequestHeader ) { this . socket . setRequestHeader ( what , this . headers [ what ] + '' ) ; } } // // Set the correct responseType method. // if ( requests . streaming ) { if ( ! this . body || 'string' === typeof this . body ) { if ( 'multipart' in socket ) { socket . multipart = true ; slice = false ; } else if ( Requests . type . mozchunkedtext ) { socket . responseType = 'moz-chunked-text' ; slice = false ; } } else { if ( Requests . type . mozchunkedarraybuffer ) { socket . responseType = 'moz-chunked-arraybuffer' ; } else if ( Requests . type . msstream ) { socket . responseType = 'ms-stream' ; } } } listeners ( socket , requests , requests . streaming ) ; requests . emit ( 'before' , socket ) ; send ( socket , this . body , hang ( function send ( err ) { if ( err ) { requests . emit ( 'error' , err ) ; requests . emit ( 'end' , err ) ; } requests . emit ( 'send' ) ; } ) ) ; }
Initialize and start requesting the supplied resource.

@param {Object} options Passed in defaults.
@api private
Initialize and start requesting the supplied resource .