<commit_before>/**********************************************************\
|                                                          |
|                          hprose                          |
|                                                          |
| Official WebSite: http://www.hprose.com/                 |
|                   http://www.hprose.org/                 |
|                                                          |
\**********************************************************/

/**********************************************************\
 *                                                        *
 * hprose/client/HttpClient.js                            *
 *                                                        *
 * Hprose Http Client for Node.js.                        *
 *                                                        *
 * LastModified: Aug 2, 2015                              *
 * Author: <NAME> <<EMAIL>>                  *
 *                                                        *
\**********************************************************/

/*jshint node:true, eqeqeq:true */
'use strict';

var util = require('util');
var http = require('http');
var https = require('https');
var parse = require('url').parse;
var TimeoutError = require('../common/TimeoutError');

var setImmediate = global.setImmediate;
var Client = global.hprose.Client;
var BytesIO = global.hprose.BytesIO;
var Future = global.hprose.Future;

function noop(){}

var s_cookieManager = {};

function setCookie(headers, host) {
    var name, value, cookies, cookie, i;
    for (name in headers) {
        value = headers[name];
        name = name.toLowerCase();
        if ((name === 'set-cookie') || (name === 'set-cookie2')) {
            cookies = value.replace(/(^\s*)|(\s*$)/g, '').split(';');
            cookie = {};
            value = cookies[0].replace(/(^\s*)|(\s*$)/g, '').split('=', 2);
            if (value[1] === undefined) value[1] = null;
            cookie.name = value[0];
            cookie.value = value[1];
            for (i = 1; i < cookies.length; i++) {
                value = cookies[i].replace(/(^\s*)|(\s*$)/g, '').split('=', 2);
                if (value[1] === undefined) value[1] = null;
                cookie[value[0].toUpperCase()] = value[1];
            }
            // Tomcat can return SetCookie2 with path wrapped in "
            if (cookie.PATH) {
                if (cookie.PATH.charAt(0) === '"') {
                    cookie.PATH = cookie.PATH.substr(1);
                }
                if (cookie.PATH.charAt(cookie.PATH.length - 1) === '"') {
                    cookie.PATH = cookie.PATH.substr(0, cookie.PATH.length - 1);
                }
            }
            else {
                cookie.PATH = '/';
            }
            if (cookie.EXPIRES) {
                cookie.EXPIRES = Date.parse(cookie.EXPIRES);
            }
            if (cookie.DOMAIN) {
                cookie.DOMAIN = cookie.DOMAIN.toLowerCase();
            }
            else {
                cookie.DOMAIN = host;
            }
            cookie.SECURE = (cookie.SECURE !== undefined);
            if (s_cookieManager[cookie.DOMAIN] === undefined) {
                s_cookieManager[cookie.DOMAIN] = {};
            }
            s_cookieManager[cookie.DOMAIN][cookie.name] = cookie;
        }
    }
}

function getCookie(host, path, secure) {
    var cookies = [];
    for (var domain in s_cookieManager) {
        if (host.indexOf(domain) > -1) {
            var names = [];
            for (var name in s_cookieManager[domain]) {
                var cookie = s_cookieManager[domain][name];
                if (cookie.EXPIRES && ((new Date()).getTime() > cookie.EXPIRES)) {
                    names.push(name);<commit_msg>Fixed setCookie of HttpClient.<commit_after>/**********************************************************\
|                                                          |
|                          hprose                          |
|                                                          |
| Official WebSite: http://www.hprose.com/                 |
|                   http://www.hprose.org/                 |
|                                                          |
\**********************************************************/

/**********************************************************\
 *                                                        *
 * hprose/client/HttpClient.js                            *
 *                                                        *
 * Hprose Http Client for Node.js.                        *
 *                                                        *
 * LastModified: Aug 5, 2015                              *
 * Author: <NAME> <<EMAIL>>                  *
 *                                                        *
\**********************************************************/

/*jshint node:true, eqeqeq:true */
'use strict';

var util = require('util');
var http = require('http');
var https = require('https');
var parse = require('url').parse;
var TimeoutError = require('../common/TimeoutError');

var setImmediate = global.setImmediate;
var Client = global.hprose.Client;
var BytesIO = global.hprose.BytesIO;
var Future = global.hprose.Future;

function noop(){}

var s_cookieManager = {};

function setCookie(headers, host) {
    var name, values;
    function _setCookie(value) {
        var cookies, cookie, i;
        cookies = value.replace(/(^\s*)|(\s*$)/g, '').split(';');
        cookie = {};
        value = cookies[0].replace(/(^\s*)|(\s*$)/g, '').split('=', 2);
        if (value[1] === undefined) value[1] = null;
        cookie.name = value[0];
        cookie.value = value[1];
        for (i = 1; i < cookies.length; i++) {
            value = cookies[i].replace(/(^\s*)|(\s*$)/g, '').split('=', 2);
            if (value[1] === undefined) value[1] = null;
            cookie[value[0].toUpperCase()] = value[1];
        }
        // Tomcat can return SetCookie2 with path wrapped in "
        if (cookie.PATH) {
            if (cookie.PATH.charAt(0) === '"') {
                cookie.PATH = cookie.PATH.substr(1);
            }
            if (cookie.PATH.charAt(cookie.PATH.length - 1) === '"') {
                cookie.PATH = cookie.PATH.substr(0, cookie.PATH.length - 1);
            }
        }
        else {
            cookie.PATH = '/';
        }
        if (cookie.EXPIRES) {
            cookie.EXPIRES = Date.parse(cookie.EXPIRES);
        }
        if (cookie.DOMAIN) {
            cookie.DOMAIN = cookie.DOMAIN.toLowerCase();
        }
        else {
            cookie.DOMAIN = host;
        }
        cookie.SECURE = (cookie.SECURE !== undefined);
        if (s_cookieManager[cookie.DOMAIN] === undefined) {
            s_cookieManager[cookie.DOMAIN] = {};
        }
        s_cookieManager[cookie.DOMAIN][cookie.name] = cookie;
    }
    for (name in headers) {
        values = headers[name];
        name = name.toLowerCase();
        if ((name === 'set-cookie') || (name === 'set-cookie2')) {
            if (typeof(values) === 'string') {
                values = [values];
            }
            values.forEach(_setCookie);
        }
    }
}

function getCookie(host, path, secure) {
    var cookies = [];
    for (var domain in s_cookieManager) {
        if (host.indexOf(domain) > -1) {
            var names = [];
            for (var name in s_cookieManager[domain]) {
                var cookie = s_cookieManager[domain][name];
                if (cookie.EXPIRES && ((new Date()).getTime() > cookie.EXPIRES)) {
                    names.push(name);
{'fraction_non_alphanumeric': 0.19727177334732424, 'fraction_numerical': 0.006558237145855194, 'mean_word_length': 1.3468759618344106, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4004591', 'n_tokens_mistral': 1981, 'n_tokens_neox': 1927, 'n_words': 379}