<commit_before>// -------------------------------------------------------------------------- \\
// File: XHR.js                                                               \\
// Module: IO                                                                 \\
// Requires: Core, Foundation                                                 \\
// Author: <NAME>                                                       \\
// License: © 2010–2012 Opera Software ASA. All rights reserved.              \\
// -------------------------------------------------------------------------- \\

/*global XMLHttpRequest, FormData, location */

"use strict";

( function ( NS ) {

var isLocal = location.protocol === 'file:';

/**
    Class: O.XHR

    Wrapper class for the native XMLHTTPRequest object in the browser. Hooks
    into the more fully featured I/O class but can be used on its own
*/
var XHR = NS.Class({
    /**
        Property (private): O.XHR#_io
        Type: Object

        Reference to object on which callbacks are made.
    */
    _io: {
        // uploadProgress: function () {},
        // loading: function () {},
        // success: function () {},
        // failure: function () {}
    },

    /**
        Property (private): O.XHR#_isRunning
        Type: Boolean

        Is a request in progress?
    */
    _isRunning: false,

    /**
        Constructor: O.XHR

        Parameters:
            io - {Object} (optional) An object containing any combination of the
                 methods 'uploadProgress', 'loading', 'success' and 'failure',
                 to be called by the XHR instance as these events occur.
    */
    init: function ( io ) {
        if ( io ) { this._io = io; }
        var xhr = this.xhr = new XMLHttpRequest(),
            that = this;
        if ( xhr.upload && io.uploadProgress ) {
            xhr.upload.addEventListener( 'progress', function ( event ) {
                io.uploadProgress( that, event );
            }.invokeInRunLoop(), false );
        }
        if ( xhr.addEventListener && io.progress ) {
            xhr.addEventListener( 'progress', function ( event ) {
                io.progress( that, event );
            }.invokeInRunLoop(), false );
        }
    },

    /**
        Method: O.XHR#isSuccess

        Determines whether a request completed successfully, as determined by
        the HTTP status code returned.

        Returns:
            {Boolean} Was the request successful?
    */
    isSuccess: function () {
        var status = this._status;
        // IE returns 200 status code when there's no network! But for a real
        // connection there must have been at least one header, so check that's
        // not empty
        return ( status >= 200 && status < 300 ) &&
            !!this.xhr.getAllResponseHeaders();
    },

    /**
        Method: O.XHR#isRunning

        Determines whether a request is currently in progress.

        Returns:
            {Boolean} Is there a request still in progress?
    */
    isRunning: function () {
        return !!this._isRunning;
    },

    /**
        Method: O.XHR#getHeader

        Returns the contents of the response header corresponding to the name
        supplied as a parameter to the method.

        Parameters:
            name - {String} The name of the header to be fetched.

        Returns:
            {String} The text of the header or the empty string if not found.
    */
    getHeader: function ( name ) {
      try {
          return this.xhr.getResponseHeader( name );
      } catch ( error ) {}
      return '';
    },

    /**
        Method: O.XHR#getResponse

        Returns the full text of the response to the request.

        Returns:
            {String} The response text.
    */
    getResponse: function () {
        // Internet Explorer may throw an error if you try to read the
        // responseText before it is in readyState 4.
        try {
            return this.xhr.responseText;
        } catch ( error ) {}
        return '';
    },

    /**
        Method: O.XHR#getResponseType

        Returns the MIME type of the response, according to the Content-type
        header set by the server.

        Returns:
            {String} The MIME type of the response.
    */
    getResponseType: function () {
        return this.getHeader( 'Content-type' );<commit_msg>Ensure XHR#get(Header|Response) returns a string.<commit_after>// -------------------------------------------------------------------------- \\
// File: XHR.js                                                               \\
// Module: IO                                                                 \\
// Requires: Core, Foundation                                                 \\
// Author: <NAME>                                                       \\
// License: © 2010–2012 Opera Software ASA. All rights reserved.              \\
// -------------------------------------------------------------------------- \\

/*global XMLHttpRequest, FormData, location */

"use strict";

( function ( NS ) {

var isLocal = location.protocol === 'file:';

/**
    Class: O.XHR

    Wrapper class for the native XMLHTTPRequest object in the browser. Hooks
    into the more fully featured I/O class but can be used on its own
*/
var XHR = NS.Class({
    /**
        Property (private): O.XHR#_io
        Type: Object

        Reference to object on which callbacks are made.
    */
    _io: {
        // uploadProgress: function () {},
        // loading: function () {},
        // success: function () {},
        // failure: function () {}
    },

    /**
        Property (private): O.XHR#_isRunning
        Type: Boolean

        Is a request in progress?
    */
    _isRunning: false,

    /**
        Constructor: O.XHR

        Parameters:
            io - {Object} (optional) An object containing any combination of the
                 methods 'uploadProgress', 'loading', 'success' and 'failure',
                 to be called by the XHR instance as these events occur.
    */
    init: function ( io ) {
        if ( io ) { this._io = io; }
        var xhr = this.xhr = new XMLHttpRequest(),
            that = this;
        if ( xhr.upload && io.uploadProgress ) {
            xhr.upload.addEventListener( 'progress', function ( event ) {
                io.uploadProgress( that, event );
            }.invokeInRunLoop(), false );
        }
        if ( xhr.addEventListener && io.progress ) {
            xhr.addEventListener( 'progress', function ( event ) {
                io.progress( that, event );
            }.invokeInRunLoop(), false );
        }
    },

    /**
        Method: O.XHR#isSuccess

        Determines whether a request completed successfully, as determined by
        the HTTP status code returned.

        Returns:
            {Boolean} Was the request successful?
    */
    isSuccess: function () {
        var status = this._status;
        // IE returns 200 status code when there's no network! But for a real
        // connection there must have been at least one header, so check that's
        // not empty
        return ( status >= 200 && status < 300 ) &&
            !!this.xhr.getAllResponseHeaders();
    },

    /**
        Method: O.XHR#isRunning

        Determines whether a request is currently in progress.

        Returns:
            {Boolean} Is there a request still in progress?
    */
    isRunning: function () {
        return !!this._isRunning;
    },

    /**
        Method: O.XHR#getHeader

        Returns the contents of the response header corresponding to the name
        supplied as a parameter to the method.

        Parameters:
            name - {String} The name of the header to be fetched.

        Returns:
            {String} The text of the header or the empty string if not found.
    */
    getHeader: function ( name ) {
        var header;
        try {
            header = this.xhr.getResponseHeader( name );
        } catch ( error ) {}
        return header || '';
    },

    /**
        Method: O.XHR#getResponse

        Returns the full text of the response to the request.

        Returns:
            {String} The response text.
    */
    getResponse: function () {
        // Internet Explorer may throw an error if you try to read the
        // responseText before it is in readyState 4.
        var response = '';
        try {
            response = this.xhr.responseText;
        } catch ( error ) {}
        return response || '';
    },

    /**
        Method: O.XHR#getResponseType

        Returns the MIME type of the response, according to the Content-type
        header set by the server.

        Returns:
            {String} The MIME type of the response.
    */
    getResponseType: function () {
        return this.getHeader( 'Content-type' );
{'fraction_non_alphanumeric': 0.1295519001701645, 'fraction_numerical': 0.0040839478162223485, 'mean_word_length': 1.3852813852813852, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3186335', 'n_tokens_mistral': 2187, 'n_tokens_neox': 2089, 'n_words': 762}