skit.define("skit.platform.net:Response", ["skit.platform.json:js","skit.platform.iter:js","skit.platform.string:js"], function() { return ((function(skit_platform_json,skit_platform_iter,skit_platform_string) { var module = {exports: {}}; var defined = null; function define() { for (var i = 0; i < arguments.length; i++) { if (typeof arguments[i] == 'function') { defined = arguments[i](); break; } } } define.amd = true; var result = (function skit_platform_net_Response() {'use strict'; /** * @class * @license * (c) 2014 Cluster Labs, Inc. https://cluster.co/ * License: MIT */ /** @ignore */ var json = skit_platform_json; /** @ignore */ var iter = skit_platform_iter; /** @ignore */ var string = skit_platform_string; function headerName(str) { return iter.map(str.split('-'), string.capitalize).join('-'); } /** * A response from the net.send() function, passed to all callbacks. * * @param {number} statusCode The status code. * @param {Object} headers The response headers. * @param {string} bodyText The body text. * @constructor */ function Response(statusCode, headers, bodyText) { this.status = statusCode; this.headers = {}; for (var key in headers) { this.headers[headerName(key)] = headers[key]; } var contentType = this.headers['Content-Type'] || ''; // Various public APIs return JSON stuff as all kinds of things. var isMaybeJSON = contentType.indexOf('/json') > -1 || contentType.indexOf('/javascript') > -1 || contentType.indexOf('/x-javascript') > -1; this.bodyText = bodyText; this.body = bodyText; if (isMaybeJSON && typeof bodyText === 'string') { try { this.body = json.parse(bodyText); } catch (e) {} } }; /** * @property {number} The response status, eg. 200. */ Response.prototype.status; /** * @property {Object} The response body. If the response's content-type * indicates that this is probably JSON, this property will be an Object. * Otherwise it will be a string. */ Response.prototype.body; /** * @property {string} The response body. Regardless of {body}, this will * be a raw string. */ Response.prototype.bodyText; /** * @property {Object} The response headers, * eg. {'Content-Type': 'application/json'}. Header names are guaranteed to * be capitalized in the form 'Content-Type'. */ Response.prototype.headers; module.exports = Response;})(); return result || defined || module.exports; })).apply(this, arguments)});