Add swagger UI
[vfc/nfvo/wfengine.git] / wfenginemgrservice / src / main / resources / api-doc / lib / shred.bundle.js
1 /*\r
2  * Copyright 2016 ZTE Corporation.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 var require = function (file, cwd) {\r
17     var resolved = require.resolve(file, cwd || '/');\r
18     var mod = require.modules[resolved];\r
19     if (!mod) throw new Error(\r
20         'Failed to resolve module ' + file + ', tried ' + resolved\r
21     );\r
22     var res = mod._cached ? mod._cached : mod();\r
23     return res;\r
24 }\r
25 \r
26 require.paths = [];\r
27 require.modules = {};\r
28 require.extensions = [".js",".coffee"];\r
29 \r
30 require._core = {\r
31     'assert': true,\r
32     'events': true,\r
33     'fs': true,\r
34     'path': true,\r
35     'vm': true\r
36 };\r
37 \r
38 require.resolve = (function () {\r
39     return function (x, cwd) {\r
40         if (!cwd) cwd = '/';\r
41         \r
42         if (require._core[x]) return x;\r
43         var path = require.modules.path();\r
44         var y = cwd || '.';\r
45         \r
46         if (x.match(/^(?:\.\.?\/|\/)/)) {\r
47             var m = loadAsFileSync(path.resolve(y, x))\r
48                 || loadAsDirectorySync(path.resolve(y, x));\r
49             if (m) return m;\r
50         }\r
51         \r
52         var n = loadNodeModulesSync(x, y);\r
53         if (n) return n;\r
54         \r
55         throw new Error("Cannot find module '" + x + "'");\r
56         \r
57         function loadAsFileSync (x) {\r
58             if (require.modules[x]) {\r
59                 return x;\r
60             }\r
61             \r
62             for (var i = 0; i < require.extensions.length; i++) {\r
63                 var ext = require.extensions[i];\r
64                 if (require.modules[x + ext]) return x + ext;\r
65             }\r
66         }\r
67         \r
68         function loadAsDirectorySync (x) {\r
69             x = x.replace(/\/+$/, '');\r
70             var pkgfile = x + '/package.json';\r
71             if (require.modules[pkgfile]) {\r
72                 var pkg = require.modules[pkgfile]();\r
73                 var b = pkg.browserify;\r
74                 if (typeof b === 'object' && b.main) {\r
75                     var m = loadAsFileSync(path.resolve(x, b.main));\r
76                     if (m) return m;\r
77                 }\r
78                 else if (typeof b === 'string') {\r
79                     var m = loadAsFileSync(path.resolve(x, b));\r
80                     if (m) return m;\r
81                 }\r
82                 else if (pkg.main) {\r
83                     var m = loadAsFileSync(path.resolve(x, pkg.main));\r
84                     if (m) return m;\r
85                 }\r
86             }\r
87             \r
88             return loadAsFileSync(x + '/index');\r
89         }\r
90         \r
91         function loadNodeModulesSync (x, start) {\r
92             var dirs = nodeModulesPathsSync(start);\r
93             for (var i = 0; i < dirs.length; i++) {\r
94                 var dir = dirs[i];\r
95                 var m = loadAsFileSync(dir + '/' + x);\r
96                 if (m) return m;\r
97                 var n = loadAsDirectorySync(dir + '/' + x);\r
98                 if (n) return n;\r
99             }\r
100             \r
101             var m = loadAsFileSync(x);\r
102             if (m) return m;\r
103         }\r
104         \r
105         function nodeModulesPathsSync (start) {\r
106             var parts;\r
107             if (start === '/') parts = [ '' ];\r
108             else parts = path.normalize(start).split('/');\r
109             \r
110             var dirs = [];\r
111             for (var i = parts.length - 1; i >= 0; i--) {\r
112                 if (parts[i] === 'node_modules') continue;\r
113                 var dir = parts.slice(0, i + 1).join('/') + '/node_modules';\r
114                 dirs.push(dir);\r
115             }\r
116             \r
117             return dirs;\r
118         }\r
119     };\r
120 })();\r
121 \r
122 require.alias = function (from, to) {\r
123     var path = require.modules.path();\r
124     var res = null;\r
125     try {\r
126         res = require.resolve(from + '/package.json', '/');\r
127     }\r
128     catch (err) {\r
129         res = require.resolve(from, '/');\r
130     }\r
131     var basedir = path.dirname(res);\r
132     \r
133     var keys = (Object.keys || function (obj) {\r
134         var res = [];\r
135         for (var key in obj) res.push(key)\r
136         return res;\r
137     })(require.modules);\r
138     \r
139     for (var i = 0; i < keys.length; i++) {\r
140         var key = keys[i];\r
141         if (key.slice(0, basedir.length + 1) === basedir + '/') {\r
142             var f = key.slice(basedir.length);\r
143             require.modules[to + f] = require.modules[basedir + f];\r
144         }\r
145         else if (key === basedir) {\r
146             require.modules[to] = require.modules[basedir];\r
147         }\r
148     }\r
149 };\r
150 \r
151 require.define = function (filename, fn) {\r
152     var dirname = require._core[filename]\r
153         ? ''\r
154         : require.modules.path().dirname(filename)\r
155     ;\r
156     \r
157     var require_ = function (file) {\r
158         return require(file, dirname)\r
159     };\r
160     require_.resolve = function (name) {\r
161         return require.resolve(name, dirname);\r
162     };\r
163     require_.modules = require.modules;\r
164     require_.define = require.define;\r
165     var module_ = { exports : {} };\r
166     \r
167     require.modules[filename] = function () {\r
168         require.modules[filename]._cached = module_.exports;\r
169         fn.call(\r
170             module_.exports,\r
171             require_,\r
172             module_,\r
173             module_.exports,\r
174             dirname,\r
175             filename\r
176         );\r
177         require.modules[filename]._cached = module_.exports;\r
178         return module_.exports;\r
179     };\r
180 };\r
181 \r
182 if (typeof process === 'undefined') process = {};\r
183 \r
184 if (!process.nextTick) process.nextTick = (function () {\r
185     var queue = [];\r
186     var canPost = typeof window !== 'undefined'\r
187         && window.postMessage && window.addEventListener\r
188     ;\r
189     \r
190     if (canPost) {\r
191         window.addEventListener('message', function (ev) {\r
192             if (ev.source === window && ev.data === 'browserify-tick') {\r
193                 ev.stopPropagation();\r
194                 if (queue.length > 0) {\r
195                     var fn = queue.shift();\r
196                     fn();\r
197                 }\r
198             }\r
199         }, true);\r
200     }\r
201     \r
202     return function (fn) {\r
203         if (canPost) {\r
204             queue.push(fn);\r
205             window.postMessage('browserify-tick', '*');\r
206         }\r
207         else setTimeout(fn, 0);\r
208     };\r
209 })();\r
210 \r
211 if (!process.title) process.title = 'browser';\r
212 \r
213 if (!process.binding) process.binding = function (name) {\r
214     if (name === 'evals') return require('vm')\r
215     else throw new Error('No such module')\r
216 };\r
217 \r
218 if (!process.cwd) process.cwd = function () { return '.' };\r
219 \r
220 require.define("path", function (require, module, exports, __dirname, __filename) {\r
221     function filter (xs, fn) {\r
222     var res = [];\r
223     for (var i = 0; i < xs.length; i++) {\r
224         if (fn(xs[i], i, xs)) res.push(xs[i]);\r
225     }\r
226     return res;\r
227 }\r
228 \r
229 // resolves . and .. elements in a path array with directory names there\r
230 // must be no slashes, empty elements, or device names (c:\) in the array\r
231 // (so also no leading and trailing slashes - it does not distinguish\r
232 // relative and absolute paths)\r
233 function normalizeArray(parts, allowAboveRoot) {\r
234   // if the path tries to go above the root, `up` ends up > 0\r
235   var up = 0;\r
236   for (var i = parts.length; i >= 0; i--) {\r
237     var last = parts[i];\r
238     if (last == '.') {\r
239       parts.splice(i, 1);\r
240     } else if (last === '..') {\r
241       parts.splice(i, 1);\r
242       up++;\r
243     } else if (up) {\r
244       parts.splice(i, 1);\r
245       up--;\r
246     }\r
247   }\r
248 \r
249   // if the path is allowed to go above the root, restore leading ..s\r
250   if (allowAboveRoot) {\r
251     for (; up--; up) {\r
252       parts.unshift('..');\r
253     }\r
254   }\r
255 \r
256   return parts;\r
257 }\r
258 \r
259 // Regex to split a filename into [*, dir, basename, ext]\r
260 // posix version\r
261 var splitPathRe = /^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;\r
262 \r
263 // path.resolve([from ...], to)\r
264 // posix version\r
265 exports.resolve = function() {\r
266 var resolvedPath = '',\r
267     resolvedAbsolute = false;\r
268 \r
269 for (var i = arguments.length; i >= -1 && !resolvedAbsolute; i--) {\r
270   var path = (i >= 0)\r
271       ? arguments[i]\r
272       : process.cwd();\r
273 \r
274   // Skip empty and invalid entries\r
275   if (typeof path !== 'string' || !path) {\r
276     continue;\r
277   }\r
278 \r
279   resolvedPath = path + '/' + resolvedPath;\r
280   resolvedAbsolute = path.charAt(0) === '/';\r
281 }\r
282 \r
283 // At this point the path should be resolved to a full absolute path, but\r
284 // handle relative paths to be safe (might happen when process.cwd() fails)\r
285 \r
286 // Normalize the path\r
287 resolvedPath = normalizeArray(filter(resolvedPath.split('/'), function(p) {\r
288     return !!p;\r
289   }), !resolvedAbsolute).join('/');\r
290 \r
291   return ((resolvedAbsolute ? '/' : '') + resolvedPath) || '.';\r
292 };\r
293 \r
294 // path.normalize(path)\r
295 // posix version\r
296 exports.normalize = function(path) {\r
297 var isAbsolute = path.charAt(0) === '/',\r
298     trailingSlash = path.slice(-1) === '/';\r
299 \r
300 // Normalize the path\r
301 path = normalizeArray(filter(path.split('/'), function(p) {\r
302     return !!p;\r
303   }), !isAbsolute).join('/');\r
304 \r
305   if (!path && !isAbsolute) {\r
306     path = '.';\r
307   }\r
308   if (path && trailingSlash) {\r
309     path += '/';\r
310   }\r
311   \r
312   return (isAbsolute ? '/' : '') + path;\r
313 };\r
314 \r
315 \r
316 // posix version\r
317 exports.join = function() {\r
318   var paths = Array.prototype.slice.call(arguments, 0);\r
319   return exports.normalize(filter(paths, function(p, index) {\r
320     return p && typeof p === 'string';\r
321   }).join('/'));\r
322 };\r
323 \r
324 \r
325 exports.dirname = function(path) {\r
326   var dir = splitPathRe.exec(path)[1] || '';\r
327   var isWindows = false;\r
328   if (!dir) {\r
329     // No dirname\r
330     return '.';\r
331   } else if (dir.length === 1 ||\r
332       (isWindows && dir.length <= 3 && dir.charAt(1) === ':')) {\r
333     // It is just a slash or a drive letter with a slash\r
334     return dir;\r
335   } else {\r
336     // It is a full dirname, strip trailing slash\r
337     return dir.substring(0, dir.length - 1);\r
338   }\r
339 };\r
340 \r
341 \r
342 exports.basename = function(path, ext) {\r
343   var f = splitPathRe.exec(path)[2] || '';\r
344   // TODO: make this comparison case-insensitive on windows?\r
345   if (ext && f.substr(-1 * ext.length) === ext) {\r
346     f = f.substr(0, f.length - ext.length);\r
347   }\r
348   return f;\r
349 };\r
350 \r
351 \r
352 exports.extname = function(path) {\r
353   return splitPathRe.exec(path)[3] || '';\r
354 };\r
355 \r
356 });\r
357 \r
358 require.define("/shred.js", function (require, module, exports, __dirname, __filename) {\r
359     // Shred is an HTTP client library intended to simplify the use of Node's\r
360 // built-in HTTP library. In particular, we wanted to make it easier to interact\r
361 // with HTTP-based APIs.\r
362 // \r
363 // See the [examples](./examples.html) for more details.\r
364 \r
365 // Ax is a nice logging library we wrote. You can use any logger, providing it\r
366 // has `info`, `warn`, `debug`, and `error` methods that take a string.\r
367 var Ax = require("ax")\r
368   , CookieJarLib = require( "cookiejar" )\r
369   , CookieJar = CookieJarLib.CookieJar\r
370 ;\r
371 \r
372 // Shred takes some options, including a logger and request defaults.\r
373 \r
374 var Shred = function(options) {\r
375   options = (options||{});\r
376   this.agent = options.agent;\r
377   this.defaults = options.defaults||{};\r
378   this.log = options.logger||(new Ax({ level: "info" }));\r
379   this._sharedCookieJar = new CookieJar();\r
380   this.logCurl = options.logCurl || false;\r
381 };\r
382 \r
383 // Most of the real work is done in the request and reponse classes.\r
384  \r
385 Shred.Request = require("./shred/request");\r
386 Shred.Response = require("./shred/response");\r
387 \r
388 // The `request` method kicks off a new request, instantiating a new `Request`\r
389 // object and passing along whatever default options we were given.\r
390 \r
391 Shred.prototype = {\r
392   request: function(options) {\r
393     options.logger = this.log;\r
394     options.logCurl = options.logCurl || this.logCurl;\r
395     options.cookieJar = ( 'cookieJar' in options ) ? options.cookieJar : this._sharedCookieJar; // let them set cookieJar = null\r
396     options.agent = options.agent || this.agent;\r
397     // fill in default options\r
398     for (var key in this.defaults) {\r
399       if (this.defaults.hasOwnProperty(key) && !options[key]) {\r
400         options[key] = this.defaults[key]\r
401       }\r
402     }\r
403     return new Shred.Request(options);\r
404   }\r
405 };\r
406 \r
407 // Define a bunch of convenience methods so that you don't have to include\r
408 // a `method` property in your request options.\r
409 \r
410 "get put post delete".split(" ").forEach(function(method) {\r
411   Shred.prototype[method] = function(options) {\r
412     options.method = method;\r
413     return this.request(options);\r
414   };\r
415 });\r
416 \r
417 \r
418 module.exports = Shred;\r
419 \r
420 });\r
421 \r
422 require.define("/node_modules/ax/package.json", function (require, module, exports, __dirname, __filename) {\r
423     module.exports = {"main":"./lib/ax.js"}\r
424 });\r
425 \r
426 require.define("/node_modules/ax/lib/ax.js", function (require, module, exports, __dirname, __filename) {\r
427     var inspect = require("util").inspect\r
428   , fs = require("fs")\r
429 ;\r
430 \r
431 \r
432 // this is a quick-and-dirty logger. there are other nicer loggers out there\r
433 // but the ones i found were also somewhat involved. this one has a Ruby\r
434 // logger type interface\r
435 //\r
436 // we can easily replace this, provide the info, debug, etc. methods are the\r
437 // same. or, we can change Haiku to use a more standard node.js interface\r
438 \r
439 var format = function(level,message) {\r
440   var debug = (level=="debug"||level=="error");\r
441   if (!message) { return message.toString(); }\r
442   if (typeof(message) == "object") {\r
443     if (message instanceof Error && debug) {\r
444       return message.stack;\r
445     } else {\r
446       return inspect(message);\r
447     }\r
448   } else {\r
449     return message.toString();\r
450   }\r
451 };\r
452 \r
453 var noOp = function(message) { return this; }\r
454 var makeLogger = function(level,fn) {\r
455   return function(message) { \r
456     this.stream.write(this.format(level, message)+"\n");\r
457     return this;\r
458   }\r
459 };\r
460 \r
461 var Logger = function(options) {\r
462   var logger = this;\r
463   var options = options||{};\r
464 \r
465   // Default options\r
466   options.level = options.level || "info";\r
467   options.timestamp = options.timestamp || true;\r
468   options.prefix = options.prefix || "";\r
469   logger.options = options;\r
470 \r
471   // Allows a prefix to be added to the message.\r
472   //\r
473   //    var logger = new Ax({ module: 'Haiku' })\r
474   //    logger.warn('this is going to be awesome!');\r
475   //    //=> Haiku: this is going to be awesome!\r
476   //\r
477   if (logger.options.module){\r
478     logger.options.prefix = logger.options.module;\r
479   }\r
480 \r
481   // Write to stderr or a file\r
482   if (logger.options.file){\r
483     logger.stream = fs.createWriteStream(logger.options.file, {"flags": "a"});\r
484   } else {\r
485       if(process.title === "node")\r
486     logger.stream = process.stderr;\r
487       else if(process.title === "browser")\r
488     logger.stream = function () {\r
489       // Work around weird console context issue: http://code.google.com/p/chromium/issues/detail?id=48662\r
490       return console[logger.options.level].apply(console, arguments);\r
491     };\r
492   }\r
493 \r
494   switch(logger.options.level){\r
495     case 'debug':\r
496       ['debug', 'info', 'warn'].forEach(function (level) {\r
497         logger[level] = Logger.writer(level);\r
498       });\r
499     case 'info':\r
500       ['info', 'warn'].forEach(function (level) {\r
501         logger[level] = Logger.writer(level);\r
502       });\r
503     case 'warn':\r
504       logger.warn = Logger.writer('warn');\r
505   }\r
506 }\r
507 \r
508 // Used to define logger methods\r
509 Logger.writer = function(level){\r
510   return function(message){\r
511     var logger = this;\r
512 \r
513     if(process.title === "node")\r
514   logger.stream.write(logger.format(level, message) + '\n');\r
515     else if(process.title === "browser")\r
516   logger.stream(logger.format(level, message) + '\n');\r
517 \r
518   };\r
519 }\r
520 \r
521 \r
522 Logger.prototype = {\r
523   info: function(){},\r
524   debug: function(){},\r
525   warn: function(){},\r
526   error: Logger.writer('error'),\r
527   format: function(level, message){\r
528     if (! message) return '';\r
529 \r
530     var logger = this\r
531       , prefix = logger.options.prefix\r
532       , timestamp = logger.options.timestamp ? " " + (new Date().toISOString()) : ""\r
533     ;\r
534 \r
535     return (prefix + timestamp + ": " + message);\r
536   }\r
537 };\r
538 \r
539 module.exports = Logger;\r
540 \r
541 });\r
542 \r
543 require.define("util", function (require, module, exports, __dirname, __filename) {\r
544     // todo\r
545 \r
546 });\r
547 \r
548 require.define("fs", function (require, module, exports, __dirname, __filename) {\r
549     // nothing to see here... no file methods for the browser\r
550 \r
551 });\r
552 \r
553 require.define("/node_modules/cookiejar/package.json", function (require, module, exports, __dirname, __filename) {\r
554     module.exports = {"main":"cookiejar.js"}\r
555 });\r
556 \r
557 require.define("/node_modules/cookiejar/cookiejar.js", function (require, module, exports, __dirname, __filename) {\r
558     exports.CookieAccessInfo=CookieAccessInfo=function CookieAccessInfo(domain,path,secure,script) {\r
559     if(this instanceof CookieAccessInfo) {\r
560       this.domain=domain||undefined;\r
561       this.path=path||"/";\r
562       this.secure=!!secure;\r
563       this.script=!!script;\r
564       return this;\r
565     }\r
566     else {\r
567         return new CookieAccessInfo(domain,path,secure,script)    \r
568     }\r
569 }\r
570 \r
571 exports.Cookie=Cookie=function Cookie(cookiestr) {\r
572   if(cookiestr instanceof Cookie) {\r
573     return cookiestr;\r
574   }\r
575     else {\r
576         if(this instanceof Cookie) {\r
577           this.name = null;\r
578           this.value = null;\r
579           this.expiration_date = Infinity;\r
580           this.path = "/";\r
581           this.domain = null;\r
582           this.secure = false; //how to define?\r
583           this.noscript = false; //httponly\r
584           if(cookiestr) {\r
585             this.parse(cookiestr)\r
586           }\r
587           return this;\r
588         }\r
589         return new Cookie(cookiestr)\r
590     }\r
591 }\r
592 \r
593 Cookie.prototype.toString = function toString() {\r
594   var str=[this.name+"="+this.value];\r
595   if(this.expiration_date !== Infinity) {\r
596     str.push("expires="+(new Date(this.expiration_date)).toGMTString());\r
597   }\r
598   if(this.domain) {\r
599     str.push("domain="+this.domain);\r
600   }\r
601   if(this.path) {\r
602     str.push("path="+this.path);\r
603   }\r
604   if(this.secure) {\r
605     str.push("secure");\r
606   }\r
607   if(this.noscript) {\r
608     str.push("httponly");\r
609   }\r
610   return str.join("; ");\r
611 }\r
612 \r
613 Cookie.prototype.toValueString = function toValueString() {\r
614   return this.name+"="+this.value;\r
615 }\r
616 \r
617 var cookie_str_splitter=/[:](?=\s*[a-zA-Z0-9_\-]+\s*[=])/g\r
618 Cookie.prototype.parse = function parse(str) {\r
619   if(this instanceof Cookie) {\r
620       var parts=str.split(";")\r
621       , pair=parts[0].match(/([^=]+)=((?:.|\n)*)/)\r
622       , key=pair[1]\r
623       , value=pair[2];\r
624       this.name = key;\r
625       this.value = value;\r
626     \r
627       for(var i=1;i<parts.length;i++) {\r
628         pair=parts[i].match(/([^=]+)(?:=((?:.|\n)*))?/)\r
629         , key=pair[1].trim().toLowerCase()\r
630         , value=pair[2];\r
631         switch(key) {\r
632           case "httponly":\r
633             this.noscript = true;\r
634           break;\r
635           case "expires":\r
636             this.expiration_date = value\r
637               ? Number(Date.parse(value))\r
638               : Infinity;\r
639           break;\r
640           case "path":\r
641             this.path = value\r
642               ? value.trim()\r
643               : "";\r
644           break;\r
645           case "domain":\r
646             this.domain = value\r
647               ? value.trim()\r
648               : "";\r
649           break;\r
650           case "secure":\r
651             this.secure = true;\r
652           break\r
653         }\r
654       }\r
655     \r
656       return this;\r
657   }\r
658     return new Cookie().parse(str)\r
659 }\r
660 \r
661 Cookie.prototype.matches = function matches(access_info) {\r
662   if(this.noscript && access_info.script\r
663   || this.secure && !access_info.secure\r
664   || !this.collidesWith(access_info)) {\r
665     return false\r
666   }\r
667   return true;\r
668 }\r
669 \r
670 Cookie.prototype.collidesWith = function collidesWith(access_info) {\r
671   if((this.path && !access_info.path) || (this.domain && !access_info.domain)) {\r
672     return false\r
673   }\r
674   if(this.path && access_info.path.indexOf(this.path) !== 0) {\r
675     return false;\r
676   }\r
677   if (this.domain===access_info.domain) {\r
678     return true;\r
679   }\r
680   else if(this.domain && this.domain.charAt(0)===".")\r
681   {\r
682     var wildcard=access_info.domain.indexOf(this.domain.slice(1))\r
683     if(wildcard===-1 || wildcard!==access_info.domain.length-this.domain.length+1) {\r
684       return false;\r
685     }\r
686   }\r
687   else if(this.domain){\r
688     return false\r
689   }\r
690   return true;\r
691 }\r
692 \r
693 exports.CookieJar=CookieJar=function CookieJar() {\r
694   if(this instanceof CookieJar) {\r
695       var cookies = {} //name: [Cookie]\r
696     \r
697       this.setCookie = function setCookie(cookie) {\r
698         cookie = Cookie(cookie);\r
699         //Delete the cookie if the set is past the current time\r
700         var remove = cookie.expiration_date <= Date.now();\r
701         if(cookie.name in cookies) {\r
702           var cookies_list = cookies[cookie.name];\r
703           for(var i=0;i<cookies_list.length;i++) {\r
704             var collidable_cookie = cookies_list[i];\r
705             if(collidable_cookie.collidesWith(cookie)) {\r
706               if(remove) {\r
707                 cookies_list.splice(i,1);\r
708                 if(cookies_list.length===0) {\r
709                   delete cookies[cookie.name]\r
710                 }\r
711                 return false;\r
712               }\r
713               else {\r
714                 return cookies_list[i]=cookie;\r
715               }\r
716             }\r
717           }\r
718           if(remove) {\r
719             return false;\r
720           }\r
721           cookies_list.push(cookie);\r
722           return cookie;\r
723         }\r
724         else if(remove){\r
725           return false;\r
726         }\r
727         else {\r
728           return cookies[cookie.name]=[cookie];\r
729         }\r
730       }\r
731       //returns a cookie\r
732       this.getCookie = function getCookie(cookie_name,access_info) {\r
733         var cookies_list = cookies[cookie_name];\r
734         for(var i=0;i<cookies_list.length;i++) {\r
735           var cookie = cookies_list[i];\r
736           if(cookie.expiration_date <= Date.now()) {\r
737             if(cookies_list.length===0) {\r
738               delete cookies[cookie.name]\r
739             }\r
740             continue;\r
741           }\r
742           if(cookie.matches(access_info)) {\r
743             return cookie;\r
744           }\r
745         }\r
746       }\r
747       //returns a list of cookies\r
748       this.getCookies = function getCookies(access_info) {\r
749         var matches=[];\r
750         for(var cookie_name in cookies) {\r
751           var cookie=this.getCookie(cookie_name,access_info);\r
752           if (cookie) {\r
753             matches.push(cookie);\r
754           }\r
755         }\r
756         matches.toString=function toString(){return matches.join(":");}\r
757             matches.toValueString=function() {return matches.map(function(c){return c.toValueString();}).join(';');}\r
758         return matches;\r
759       }\r
760     \r
761       return this;\r
762   }\r
763     return new CookieJar()\r
764 }\r
765 \r
766 \r
767 //returns list of cookies that were set correctly\r
768 CookieJar.prototype.setCookies = function setCookies(cookies) {\r
769   cookies=Array.isArray(cookies)\r
770     ?cookies\r
771     :cookies.split(cookie_str_splitter);\r
772   var successful=[]\r
773   for(var i=0;i<cookies.length;i++) {\r
774     var cookie = Cookie(cookies[i]);\r
775     if(this.setCookie(cookie)) {\r
776       successful.push(cookie);\r
777     }\r
778   }\r
779   return successful;\r
780 }\r
781 \r
782 });\r
783 \r
784 require.define("/shred/request.js", function (require, module, exports, __dirname, __filename) {\r
785     // The request object encapsulates a request, creating a Node.js HTTP request and\r
786 // then handling the response.\r
787 \r
788 var HTTP = require("http")\r
789   , HTTPS = require("https")\r
790   , parseUri = require("./parseUri")\r
791   , Emitter = require('events').EventEmitter\r
792   , sprintf = require("sprintf").sprintf\r
793   , Response = require("./response")\r
794   , HeaderMixins = require("./mixins/headers")\r
795   , Content = require("./content")\r
796 ;\r
797 \r
798 var STATUS_CODES = HTTP.STATUS_CODES || {\r
799     100 : 'Continue',\r
800     101 : 'Switching Protocols',\r
801     102 : 'Processing', // RFC 2518, obsoleted by RFC 4918\r
802     200 : 'OK',\r
803     201 : 'Created',\r
804     202 : 'Accepted',\r
805     203 : 'Non-Authoritative Information',\r
806     204 : 'No Content',\r
807     205 : 'Reset Content',\r
808     206 : 'Partial Content',\r
809     207 : 'Multi-Status', // RFC 4918\r
810     300 : 'Multiple Choices',\r
811     301 : 'Moved Permanently',\r
812     302 : 'Moved Temporarily',\r
813     303 : 'See Other',\r
814     304 : 'Not Modified',\r
815     305 : 'Use Proxy',\r
816     307 : 'Temporary Redirect',\r
817     400 : 'Bad Request',\r
818     401 : 'Unauthorized',\r
819     402 : 'Payment Required',\r
820     403 : 'Forbidden',\r
821     404 : 'Not Found',\r
822     405 : 'Method Not Allowed',\r
823     406 : 'Not Acceptable',\r
824     407 : 'Proxy Authentication Required',\r
825     408 : 'Request Time-out',\r
826     409 : 'Conflict',\r
827     410 : 'Gone',\r
828     411 : 'Length Required',\r
829     412 : 'Precondition Failed',\r
830     413 : 'Request Entity Too Large',\r
831     414 : 'Request-URI Too Large',\r
832     415 : 'Unsupported Media Type',\r
833     416 : 'Requested Range Not Satisfiable',\r
834     417 : 'Expectation Failed',\r
835     418 : 'I\'m a teapot', // RFC 2324\r
836     422 : 'Unprocessable Entity', // RFC 4918\r
837     423 : 'Locked', // RFC 4918\r
838     424 : 'Failed Dependency', // RFC 4918\r
839     425 : 'Unordered Collection', // RFC 4918\r
840     426 : 'Upgrade Required', // RFC 2817\r
841     500 : 'Internal Server Error',\r
842     501 : 'Not Implemented',\r
843     502 : 'Bad Gateway',\r
844     503 : 'Service Unavailable',\r
845     504 : 'Gateway Time-out',\r
846     505 : 'HTTP Version not supported',\r
847     506 : 'Variant Also Negotiates', // RFC 2295\r
848     507 : 'Insufficient Storage', // RFC 4918\r
849     509 : 'Bandwidth Limit Exceeded',\r
850     510 : 'Not Extended' // RFC 2774\r
851 };\r
852 \r
853 // The Shred object itself constructs the `Request` object. You should rarely\r
854 // need to do this directly.\r
855 \r
856 var Request = function(options) {\r
857   this.log = options.logger;\r
858   this.cookieJar = options.cookieJar;\r
859   this.encoding = options.encoding;\r
860   this.logCurl = options.logCurl;\r
861   processOptions(this,options||{});\r
862   createRequest(this);\r
863 };\r
864 \r
865 // A `Request` has a number of properties, many of which help with details like\r
866 // URL parsing or defaulting the port for the request.\r
867 \r
868 Object.defineProperties(Request.prototype, {\r
869 \r
870 // - **url**. You can set the `url` property with a valid URL string and all the\r
871 //   URL-related properties (host, port, etc.) will be automatically set on the\r
872 //   request object.\r
873 \r
874   url: {\r
875     get: function() {\r
876       if (!this.scheme) { return null; }\r
877       return sprintf("%s://%s:%s%s",\r
878           this.scheme, this.host, this.port,\r
879           (this.proxy ? "/" : this.path) +\r
880           (this.query ? ("?" + this.query) : ""));\r
881     },\r
882     set: function(_url) {\r
883       _url = parseUri(_url);\r
884       this.scheme = _url.protocol;\r
885       this.host = _url.host;\r
886       this.port = _url.port;\r
887       this.path = _url.path;\r
888       this.query = _url.query;\r
889       return this;\r
890     },\r
891     enumerable: true\r
892   },\r
893 \r
894 // - **headers**. Returns a hash representing the request headers. You can't set\r
895 //   this directly, only get it. You can add or modify headers by using the\r
896 //   `setHeader` or `setHeaders` method. This ensures that the headers are\r
897 //   normalized - that is, you don't accidentally send `Content-Type` and\r
898 //   `content-type` headers. Keep in mind that if you modify the returned hash,\r
899 //   it will *not* modify the request headers.\r
900 \r
901   headers: {\r
902     get: function() {\r
903       return this.getHeaders();\r
904     },\r
905     enumerable: true\r
906   },\r
907 \r
908 // - **port**. Unless you set the `port` explicitly or include it in the URL, it\r
909 //   will default based on the scheme.\r
910 \r
911   port: {\r
912     get: function() {\r
913       if (!this._port) {\r
914         switch(this.scheme) {\r
915           case "https": return this._port = 443;\r
916           case "http":\r
917           default: return this._port = 80;\r
918         }\r
919       }\r
920       return this._port;\r
921     },\r
922     set: function(value) { this._port = value; return this; },\r
923     enumerable: true\r
924   },\r
925 \r
926 // - **method**. The request method - `get`, `put`, `post`, etc. that will be\r
927 //   used to make the request. Defaults to `get`.\r
928 \r
929   method: {\r
930     get: function() {\r
931       return this._method = (this._method||"GET");\r
932     },\r
933     set: function(value) {\r
934       this._method = value; return this;\r
935     },\r
936     enumerable: true\r
937   },\r
938 \r
939 // - **query**. Can be set either with a query string or a hash (object). Get\r
940 //   will always return a properly escaped query string or null if there is no\r
941 //   query component for the request.\r
942 \r
943   query: {\r
944     get: function() {return this._query;},\r
945     set: function(value) {\r
946       var stringify = function (hash) {\r
947         var query = "";\r
948         for (var key in hash) {\r
949           query += encodeURIComponent(key) + '=' + encodeURIComponent(hash[key]) + '&';\r
950         }\r
951         // Remove the last '&'\r
952         query = query.slice(0, -1);\r
953         return query;\r
954       }\r
955 \r
956       if (value) {\r
957         if (typeof value === 'object') {\r
958           value = stringify(value);\r
959         }\r
960         this._query = value;\r
961       } else {\r
962         this._query = "";\r
963       }\r
964       return this;\r
965     },\r
966     enumerable: true\r
967   },\r
968 \r
969 // - **parameters**. This will return the query parameters in the form of a hash\r
970 //   (object).\r
971 \r
972   parameters: {\r
973     get: function() { return QueryString.parse(this._query||""); },\r
974     enumerable: true\r
975   },\r
976 \r
977 // - **content**. (Aliased as `body`.) Set this to add a content entity to the\r
978 //   request. Attempts to use the `content-type` header to determine what to do\r
979 //   with the content value. Get this to get back a [`Content`\r
980 //   object](./content.html).\r
981 \r
982   body: {\r
983     get: function() { return this._body; },\r
984     set: function(value) {\r
985       this._body = new Content({\r
986         data: value,\r
987         type: this.getHeader("Content-Type")\r
988       });\r
989       this.setHeader("Content-Type",this.content.type);\r
990       this.setHeader("Content-Length",this.content.length);\r
991       return this;\r
992     },\r
993     enumerable: true\r
994   },\r
995 \r
996 // - **timeout**. Used to determine how long to wait for a response. Does not\r
997 //   distinguish between connect timeouts versus request timeouts. Set either in\r
998 //   milliseconds or with an object with temporal attributes (hours, minutes,\r
999 //   seconds) and convert it into milliseconds. Get will always return\r
1000 //   milliseconds.\r
1001 \r
1002   timeout: {\r
1003     get: function() { return this._timeout; }, // in milliseconds\r
1004     set: function(timeout) {\r
1005       var request = this\r
1006         , milliseconds = 0;\r
1007       ;\r
1008       if (!timeout) return this;\r
1009       if (typeof timeout==="number") { milliseconds = timeout; }\r
1010       else {\r
1011         milliseconds = (timeout.milliseconds||0) +\r
1012           (1000 * ((timeout.seconds||0) +\r
1013               (60 * ((timeout.minutes||0) +\r
1014                 (60 * (timeout.hours||0))))));\r
1015       }\r
1016       this._timeout = milliseconds;\r
1017       return this;\r
1018     },\r
1019     enumerable: true\r
1020   }\r
1021 });\r
1022 \r
1023 // Alias `body` property to `content`. Since the [content object](./content.html)\r
1024 // has a `body` attribute, it's preferable to use `content` since you can then\r
1025 // access the raw content data using `content.body`.\r
1026 \r
1027 Object.defineProperty(Request.prototype,"content",\r
1028     Object.getOwnPropertyDescriptor(Request.prototype, "body"));\r
1029 \r
1030 // The `Request` object can be pretty overwhelming to view using the built-in\r
1031 // Node.js inspect method. We want to make it a bit more manageable. This\r
1032 // probably goes [too far in the other\r
1033 // direction](https://github.com/spire-io/shred/issues/2).\r
1034 \r
1035 Request.prototype.inspect = function () {\r
1036   var request = this;\r
1037   var headers = this.format_headers();\r
1038   var summary = ["<Shred Request> ", request.method.toUpperCase(),\r
1039       request.url].join(" ")\r
1040   return [ summary, "- Headers:", headers].join("\n");\r
1041 };\r
1042 \r
1043 Request.prototype.format_headers = function () {\r
1044   var array = []\r
1045   var headers = this._headers\r
1046   for (var key in headers) {\r
1047     if (headers.hasOwnProperty(key)) {\r
1048       var value = headers[key]\r
1049       array.push("\t" + key + ": " + value);\r
1050     }\r
1051   }\r
1052   return array.join("\n");\r
1053 };\r
1054 \r
1055 // Allow chainable 'on's:  shred.get({ ... }).on( ... ).  You can pass in a\r
1056 // single function, a pair (event, function), or a hash:\r
1057 // { event: function, event: function }\r
1058 Request.prototype.on = function (eventOrHash, listener) {\r
1059   var emitter = this.emitter;\r
1060   // Pass in a single argument as a function then make it the default response handler\r
1061   if (arguments.length === 1 && typeof(eventOrHash) === 'function') {\r
1062     emitter.on('response', eventOrHash);\r
1063   } else if (arguments.length === 1 && typeof(eventOrHash) === 'object') {\r
1064     for (var key in eventOrHash) {\r
1065       if (eventOrHash.hasOwnProperty(key)) {\r
1066         emitter.on(key, eventOrHash[key]);\r
1067       }\r
1068     }\r
1069   } else {\r
1070     emitter.on(eventOrHash, listener);\r
1071   }\r
1072   return this;\r
1073 };\r
1074 \r
1075 // Add in the header methods. Again, these ensure we don't get the same header\r
1076 // multiple times with different case conventions.\r
1077 HeaderMixins.gettersAndSetters(Request);\r
1078 \r
1079 // `processOptions` is called from the constructor to handle all the work\r
1080 // associated with making sure we do our best to ensure we have a valid request.\r
1081 \r
1082 var processOptions = function(request,options) {\r
1083 \r
1084   request.log.debug("Processing request options ..");\r
1085 \r
1086   // We'll use `request.emitter` to manage the `on` event handlers.\r
1087   request.emitter = (new Emitter);\r
1088 \r
1089   request.agent = options.agent;\r
1090 \r
1091   // Set up the handlers ...\r
1092   if (options.on) {\r
1093     for (var key in options.on) {\r
1094       if (options.on.hasOwnProperty(key)) {\r
1095         request.emitter.on(key, options.on[key]);\r
1096       }\r
1097     }\r
1098   }\r
1099 \r
1100   // Make sure we were give a URL or a host\r
1101   if (!options.url && !options.host) {\r
1102     request.emitter.emit("request_error",\r
1103         new Error("No url or url options (host, port, etc.)"));\r
1104     return;\r
1105   }\r
1106 \r
1107   // Allow for the [use of a proxy](http://www.jmarshall.com/easy/http/#proxies).\r
1108 \r
1109   if (options.url) {\r
1110     if (options.proxy) {\r
1111       request.url = options.proxy;\r
1112       request.path = options.url;\r
1113     } else {\r
1114       request.url = options.url;\r
1115     }\r
1116   }\r
1117 \r
1118   // Set the remaining options.\r
1119   request.query = options.query||options.parameters||request.query ;\r
1120   request.method = options.method;\r
1121   request.setHeader("user-agent",options.agent||"Shred");\r
1122   request.setHeaders(options.headers);\r
1123 \r
1124   if (request.cookieJar) {\r
1125     var cookies = request.cookieJar.getCookies( CookieAccessInfo( request.host, request.path ) );\r
1126     if (cookies.length) {\r
1127       var cookieString = request.getHeader('cookie')||'';\r
1128       for (var cookieIndex = 0; cookieIndex < cookies.length; ++cookieIndex) {\r
1129           if ( cookieString.length && cookieString[ cookieString.length - 1 ] != ';' )\r
1130           {\r
1131               cookieString += ';';\r
1132           }\r
1133           cookieString += cookies[ cookieIndex ].name + '=' + cookies[ cookieIndex ].value + ';';\r
1134       }\r
1135       request.setHeader("cookie", cookieString);\r
1136     }\r
1137   }\r
1138   \r
1139   // The content entity can be set either using the `body` or `content` attributes.\r
1140   if (options.body||options.content) {\r
1141     request.content = options.body||options.content;\r
1142   }\r
1143   request.timeout = options.timeout;\r
1144 \r
1145 };\r
1146 \r
1147 // `createRequest` is also called by the constructor, after `processOptions`.\r
1148 // This actually makes the request and processes the response, so `createRequest`\r
1149 // is a bit of a misnomer.\r
1150 \r
1151 var createRequest = function(request) {\r
1152   var timeout ;\r
1153 \r
1154   request.log.debug("Creating request ..");\r
1155   request.log.debug(request);\r
1156 \r
1157   var reqParams = {\r
1158     host: request.host,\r
1159     port: request.port,\r
1160     method: request.method,\r
1161     path: request.path + (request.query ? '?'+request.query : ""),\r
1162     headers: request.getHeaders(),\r
1163     // Node's HTTP/S modules will ignore this, but we are using the\r
1164     // browserify-http module in the browser for both HTTP and HTTPS, and this\r
1165     // is how you differentiate the two.\r
1166     scheme: request.scheme,\r
1167     // Use a provided agent.  'Undefined' is the default, which uses a global\r
1168     // agent.\r
1169     agent: request.agent\r
1170   };\r
1171 \r
1172   if (request.logCurl) {\r
1173     logCurl(request);\r
1174   }\r
1175 \r
1176   var http = request.scheme == "http" ? HTTP : HTTPS;\r
1177 \r
1178   // Set up the real request using the selected library. The request won't be\r
1179   // sent until we call `.end()`.\r
1180   request._raw = http.request(reqParams, function(response) {\r
1181     request.log.debug("Received response ..");\r
1182 \r
1183     // We haven't timed out and we have a response, so make sure we clear the\r
1184     // timeout so it doesn't fire while we're processing the response.\r
1185     clearTimeout(timeout);\r
1186 \r
1187     // Construct a Shred `Response` object from the response. This will stream\r
1188     // the response, thus the need for the callback. We can access the response\r
1189     // entity safely once we're in the callback.\r
1190     response = new Response(response, request, function(response) {\r
1191 \r
1192       // Set up some event magic. The precedence is given first to\r
1193       // status-specific handlers, then to responses for a given event, and then\r
1194       // finally to the more general `response` handler. In the last case, we\r
1195       // need to first make sure we're not dealing with a a redirect.\r
1196       var emit = function(event) {\r
1197         var emitter = request.emitter;\r
1198         var textStatus = STATUS_CODES[response.status] ? STATUS_CODES[response.status].toLowerCase() : null;\r
1199         if (emitter.listeners(response.status).length > 0 || emitter.listeners(textStatus).length > 0) {\r
1200           emitter.emit(response.status, response);\r
1201           emitter.emit(textStatus, response);\r
1202         } else {\r
1203           if (emitter.listeners(event).length>0) {\r
1204             emitter.emit(event, response);\r
1205           } else if (!response.isRedirect) {\r
1206             emitter.emit("response", response);\r
1207             //console.warn("Request has no event listener for status code " + response.status);\r
1208           }\r
1209         }\r
1210       };\r
1211 \r
1212       // Next, check for a redirect. We simply repeat the request with the URL\r
1213       // given in the `Location` header. We fire a `redirect` event.\r
1214       if (response.isRedirect) {\r
1215         request.log.debug("Redirecting to "\r
1216             + response.getHeader("Location"));\r
1217         request.url = response.getHeader("Location");\r
1218         emit("redirect");\r
1219         createRequest(request);\r
1220 \r
1221       // Okay, it's not a redirect. Is it an error of some kind?\r
1222       } else if (response.isError) {\r
1223         emit("error");\r
1224       } else {\r
1225       // It looks like we're good shape. Trigger the `success` event.\r
1226         emit("success");\r
1227       }\r
1228     });\r
1229   });\r
1230 \r
1231   // We're still setting up the request. Next, we're going to handle error cases\r
1232   // where we have no response. We don't emit an error event because that event\r
1233   // takes a response. We don't response handlers to have to check for a null\r
1234   // value. However, we [should introduce a different event\r
1235   // type](https://github.com/spire-io/shred/issues/3) for this type of error.\r
1236   request._raw.on("error", function(error) {\r
1237     request.emitter.emit("request_error", error);\r
1238   });\r
1239 \r
1240   request._raw.on("socket", function(socket) {\r
1241     request.emitter.emit("socket", socket);\r
1242   });\r
1243 \r
1244   // TCP timeouts should also trigger the "response_error" event.\r
1245   request._raw.on('socket', function () {\r
1246     request._raw.socket.on('timeout', function () {\r
1247       // This should trigger the "error" event on the raw request, which will\r
1248       // trigger the "response_error" on the shred request.\r
1249       request._raw.abort();\r
1250     });\r
1251   });\r
1252 \r
1253 \r
1254   // We're almost there. Next, we need to write the request entity to the\r
1255   // underlying request object.\r
1256   if (request.content) {\r
1257     request.log.debug("Streaming body: '" +\r
1258         request.content.data.slice(0,59) + "' ... ");\r
1259     request._raw.write(request.content.data);\r
1260   }\r
1261 \r
1262   // Finally, we need to set up the timeout. We do this last so that we don't\r
1263   // start the clock ticking until the last possible moment.\r
1264   if (request.timeout) {\r
1265     timeout = setTimeout(function() {\r
1266       request.log.debug("Timeout fired, aborting request ...");\r
1267       request._raw.abort();\r
1268       request.emitter.emit("timeout", request);\r
1269     },request.timeout);\r
1270   }\r
1271 \r
1272   // The `.end()` method will cause the request to fire. Technically, it might\r
1273   // have already sent the headers and body.\r
1274   request.log.debug("Sending request ...");\r
1275   request._raw.end();\r
1276 };\r
1277 \r
1278 // Logs the curl command for the request.\r
1279 var logCurl = function (req) {\r
1280   var headers = req.getHeaders();\r
1281   var headerString = "";\r
1282 \r
1283   for (var key in headers) {\r
1284     headerString += '-H "' + key + ": " + headers[key] + '" ';\r
1285   }\r
1286 \r
1287   var bodyString = ""\r
1288 \r
1289   if (req.content) {\r
1290     bodyString += "-d '" + req.content.body + "' ";\r
1291   }\r
1292 \r
1293   var query = req.query ? '?' + req.query : "";\r
1294 \r
1295   console.log("curl " +\r
1296     "-X " + req.method.toUpperCase() + " " +\r
1297     req.scheme + "://" + req.host + ":" + req.port + req.path + query + " " +\r
1298     headerString +\r
1299     bodyString\r
1300   );\r
1301 };\r
1302 \r
1303 \r
1304 module.exports = Request;\r
1305 \r
1306 });\r
1307 \r
1308 require.define("http", function (require, module, exports, __dirname, __filename) {\r
1309     // todo\r
1310 \r
1311 });\r
1312 \r
1313 require.define("https", function (require, module, exports, __dirname, __filename) {\r
1314     // todo\r
1315 \r
1316 });\r
1317 \r
1318 require.define("/shred/parseUri.js", function (require, module, exports, __dirname, __filename) {\r
1319     // parseUri 1.2.2\r
1320 // (c) Steven Levithan <stevenlevithan.com>\r
1321 // MIT License\r
1322 \r
1323 function parseUri (str) {\r
1324   var o   = parseUri.options,\r
1325     m   = o.parser[o.strictMode ? "strict" : "loose"].exec(str),\r
1326     uri = {},\r
1327     i   = 14;\r
1328 \r
1329   while (i--) uri[o.key[i]] = m[i] || "";\r
1330 \r
1331   uri[o.q.name] = {};\r
1332   uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {\r
1333     if ($1) uri[o.q.name][$1] = $2;\r
1334   });\r
1335 \r
1336   return uri;\r
1337 };\r
1338 \r
1339 parseUri.options = {\r
1340   strictMode: false,\r
1341   key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],\r
1342   q:   {\r
1343     name:   "queryKey",\r
1344     parser: /(?:^|&)([^&=]*)=?([^&]*)/g\r
1345   },\r
1346   parser: {\r
1347     strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,\r
1348     loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/\r
1349   }\r
1350 };\r
1351 \r
1352 module.exports = parseUri;\r
1353 \r
1354 });\r
1355 \r
1356 require.define("events", function (require, module, exports, __dirname, __filename) {\r
1357     if (!process.EventEmitter) process.EventEmitter = function () {};\r
1358 \r
1359 var EventEmitter = exports.EventEmitter = process.EventEmitter;\r
1360 var isArray = typeof Array.isArray === 'function'\r
1361     ? Array.isArray\r
1362     : function (xs) {\r
1363         return Object.toString.call(xs) === '[object Array]'\r
1364     }\r
1365 ;\r
1366 \r
1367 // By default EventEmitters will print a warning if more than\r
1368 // 10 listeners are added to it. This is a useful default which\r
1369 // helps finding memory leaks.\r
1370 //\r
1371 // Obviously not all Emitters should be limited to 10. This function allows\r
1372 // that to be increased. Set to zero for unlimited.\r
1373 var defaultMaxListeners = 10;\r
1374 EventEmitter.prototype.setMaxListeners = function(n) {\r
1375   if (!this._events) this._events = {};\r
1376   this._events.maxListeners = n;\r
1377 };\r
1378 \r
1379 \r
1380 EventEmitter.prototype.emit = function(type) {\r
1381   // If there is no 'error' event listener then throw.\r
1382   if (type === 'error') {\r
1383     if (!this._events || !this._events.error ||\r
1384         (isArray(this._events.error) && !this._events.error.length))\r
1385     {\r
1386       if (arguments[1] instanceof Error) {\r
1387         throw arguments[1]; // Unhandled 'error' event\r
1388       } else {\r
1389         throw new Error("Uncaught, unspecified 'error' event.");\r
1390       }\r
1391       return false;\r
1392     }\r
1393   }\r
1394 \r
1395   if (!this._events) return false;\r
1396   var handler = this._events[type];\r
1397   if (!handler) return false;\r
1398 \r
1399   if (typeof handler == 'function') {\r
1400     switch (arguments.length) {\r
1401       // fast cases\r
1402       case 1:\r
1403         handler.call(this);\r
1404         break;\r
1405       case 2:\r
1406         handler.call(this, arguments[1]);\r
1407         break;\r
1408       case 3:\r
1409         handler.call(this, arguments[1], arguments[2]);\r
1410         break;\r
1411       // slower\r
1412       default:\r
1413         var args = Array.prototype.slice.call(arguments, 1);\r
1414         handler.apply(this, args);\r
1415     }\r
1416     return true;\r
1417 \r
1418   } else if (isArray(handler)) {\r
1419     var args = Array.prototype.slice.call(arguments, 1);\r
1420 \r
1421     var listeners = handler.slice();\r
1422     for (var i = 0, l = listeners.length; i < l; i++) {\r
1423       listeners[i].apply(this, args);\r
1424     }\r
1425     return true;\r
1426 \r
1427   } else {\r
1428     return false;\r
1429   }\r
1430 };\r
1431 \r
1432 // EventEmitter is defined in src/node_events.cc\r
1433 // EventEmitter.prototype.emit() is also defined there.\r
1434 EventEmitter.prototype.addListener = function(type, listener) {\r
1435   if ('function' !== typeof listener) {\r
1436     throw new Error('addListener only takes instances of Function');\r
1437   }\r
1438 \r
1439   if (!this._events) this._events = {};\r
1440 \r
1441   // To avoid recursion in the case that type == "newListeners"! Before\r
1442   // adding it to the listeners, first emit "newListeners".\r
1443   this.emit('newListener', type, listener);\r
1444 \r
1445   if (!this._events[type]) {\r
1446     // Optimize the case of one listener. Don't need the extra array object.\r
1447     this._events[type] = listener;\r
1448   } else if (isArray(this._events[type])) {\r
1449 \r
1450     // Check for listener leak\r
1451     if (!this._events[type].warned) {\r
1452       var m;\r
1453       if (this._events.maxListeners !== undefined) {\r
1454         m = this._events.maxListeners;\r
1455       } else {\r
1456         m = defaultMaxListeners;\r
1457       }\r
1458 \r
1459       if (m && m > 0 && this._events[type].length > m) {\r
1460         this._events[type].warned = true;\r
1461         console.error('(node) warning: possible EventEmitter memory ' +\r
1462                       'leak detected. %d listeners added. ' +\r
1463                       'Use emitter.setMaxListeners() to increase limit.',\r
1464                       this._events[type].length);\r
1465         console.trace();\r
1466       }\r
1467     }\r
1468 \r
1469     // If we've already got an array, just append.\r
1470     this._events[type].push(listener);\r
1471   } else {\r
1472     // Adding the second element, need to change to array.\r
1473     this._events[type] = [this._events[type], listener];\r
1474   }\r
1475 \r
1476   return this;\r
1477 };\r
1478 \r
1479 EventEmitter.prototype.on = EventEmitter.prototype.addListener;\r
1480 \r
1481 EventEmitter.prototype.once = function(type, listener) {\r
1482   var self = this;\r
1483   self.on(type, function g() {\r
1484     self.removeListener(type, g);\r
1485     listener.apply(this, arguments);\r
1486   });\r
1487 \r
1488   return this;\r
1489 };\r
1490 \r
1491 EventEmitter.prototype.removeListener = function(type, listener) {\r
1492   if ('function' !== typeof listener) {\r
1493     throw new Error('removeListener only takes instances of Function');\r
1494   }\r
1495 \r
1496   // does not use listeners(), so no side effect of creating _events[type]\r
1497   if (!this._events || !this._events[type]) return this;\r
1498 \r
1499   var list = this._events[type];\r
1500 \r
1501   if (isArray(list)) {\r
1502     var i = list.indexOf(listener);\r
1503     if (i < 0) return this;\r
1504     list.splice(i, 1);\r
1505     if (list.length == 0)\r
1506       delete this._events[type];\r
1507   } else if (this._events[type] === listener) {\r
1508     delete this._events[type];\r
1509   }\r
1510 \r
1511   return this;\r
1512 };\r
1513 \r
1514 EventEmitter.prototype.removeAllListeners = function(type) {\r
1515   // does not use listeners(), so no side effect of creating _events[type]\r
1516   if (type && this._events && this._events[type]) this._events[type] = null;\r
1517   return this;\r
1518 };\r
1519 \r
1520 EventEmitter.prototype.listeners = function(type) {\r
1521   if (!this._events) this._events = {};\r
1522   if (!this._events[type]) this._events[type] = [];\r
1523   if (!isArray(this._events[type])) {\r
1524     this._events[type] = [this._events[type]];\r
1525   }\r
1526   return this._events[type];\r
1527 };\r
1528 \r
1529 });\r
1530 \r
1531 require.define("/node_modules/sprintf/package.json", function (require, module, exports, __dirname, __filename) {\r
1532     module.exports = {"main":"./lib/sprintf"}\r
1533 });\r
1534 \r
1535 require.define("/node_modules/sprintf/lib/sprintf.js", function (require, module, exports, __dirname, __filename) {\r
1536     /**\r
1537 sprintf() for JavaScript 0.7-beta1\r
1538 http://www.diveintojavascript.com/projects/javascript-sprintf\r
1539 \r
1540 Copyright (c) Alexandru Marasteanu <alexaholic [at) gmail (dot] com>\r
1541 All rights reserved.\r
1542 \r
1543 Redistribution and use in source and binary forms, with or without\r
1544 modification, are permitted provided that the following conditions are met:\r
1545     * Redistributions of source code must retain the above copyright\r
1546       notice, this list of conditions and the following disclaimer.\r
1547     * Redistributions in binary form must reproduce the above copyright\r
1548       notice, this list of conditions and the following disclaimer in the\r
1549       documentation and/or other materials provided with the distribution.\r
1550     * Neither the name of sprintf() for JavaScript nor the\r
1551       names of its contributors may be used to endorse or promote products\r
1552       derived from this software without specific prior written permission.\r
1553 \r
1554 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND\r
1555 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\r
1556 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
1557 DISCLAIMED. IN NO EVENT SHALL Alexandru Marasteanu BE LIABLE FOR ANY\r
1558 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\r
1559 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
1560 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\r
1561 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
1562 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
1563 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
1564 \r
1565 \r
1566 Changelog:\r
1567 2010.11.07 - 0.7-beta1-node\r
1568   - converted it to a node.js compatible module\r
1569 \r
1570 2010.09.06 - 0.7-beta1\r
1571   - features: vsprintf, support for named placeholders\r
1572   - enhancements: format cache, reduced global namespace pollution\r
1573 \r
1574 2010.05.22 - 0.6:\r
1575  - reverted to 0.4 and fixed the bug regarding the sign of the number 0\r
1576  Note:\r
1577  Thanks to Raphael Pigulla <raph (at] n3rd [dot) org> (http://www.n3rd.org/)\r
1578  who warned me about a bug in 0.5, I discovered that the last update was\r
1579  a regress. I appologize for that.\r
1580 \r
1581 2010.05.09 - 0.5:\r
1582  - bug fix: 0 is now preceeded with a + sign\r
1583  - bug fix: the sign was not at the right position on padded results (Kamal Abdali)\r
1584  - switched from GPL to BSD license\r
1585 \r
1586 2007.10.21 - 0.4:\r
1587  - unit test and patch (David Baird)\r
1588 \r
1589 2007.09.17 - 0.3:\r
1590  - bug fix: no longer throws exception on empty paramenters (Hans Pufal)\r
1591 \r
1592 2007.09.11 - 0.2:\r
1593  - feature: added argument swapping\r
1594 \r
1595 2007.04.03 - 0.1:\r
1596  - initial release\r
1597 **/\r
1598 \r
1599 var sprintf = (function() {\r
1600   function get_type(variable) {\r
1601     return Object.prototype.toString.call(variable).slice(8, -1).toLowerCase();\r
1602   }\r
1603   function str_repeat(input, multiplier) {\r
1604     for (var output = []; multiplier > 0; output[--multiplier] = input) {/* do nothing */}\r
1605     return output.join('');\r
1606   }\r
1607 \r
1608   var str_format = function() {\r
1609     if (!str_format.cache.hasOwnProperty(arguments[0])) {\r
1610       str_format.cache[arguments[0]] = str_format.parse(arguments[0]);\r
1611     }\r
1612     return str_format.format.call(null, str_format.cache[arguments[0]], arguments);\r
1613   };\r
1614 \r
1615   str_format.format = function(parse_tree, argv) {\r
1616     var cursor = 1, tree_length = parse_tree.length, node_type = '', arg, output = [], i, k, match, pad, pad_character, pad_length;\r
1617     for (i = 0; i < tree_length; i++) {\r
1618       node_type = get_type(parse_tree[i]);\r
1619       if (node_type === 'string') {\r
1620         output.push(parse_tree[i]);\r
1621       }\r
1622       else if (node_type === 'array') {\r
1623         match = parse_tree[i]; // convenience purposes only\r
1624         if (match[2]) { // keyword argument\r
1625           arg = argv[cursor];\r
1626           for (k = 0; k < match[2].length; k++) {\r
1627             if (!arg.hasOwnProperty(match[2][k])) {\r
1628               throw(sprintf('[sprintf] property "%s" does not exist', match[2][k]));\r
1629             }\r
1630             arg = arg[match[2][k]];\r
1631           }\r
1632         }\r
1633         else if (match[1]) { // positional argument (explicit)\r
1634           arg = argv[match[1]];\r
1635         }\r
1636         else { // positional argument (implicit)\r
1637           arg = argv[cursor++];\r
1638         }\r
1639 \r
1640         if (/[^s]/.test(match[8]) && (get_type(arg) != 'number')) {\r
1641           throw(sprintf('[sprintf] expecting number but found %s', get_type(arg)));\r
1642         }\r
1643         switch (match[8]) {\r
1644           case 'b': arg = arg.toString(2); break;\r
1645           case 'c': arg = String.fromCharCode(arg); break;\r
1646           case 'd': arg = parseInt(arg, 10); break;\r
1647           case 'e': arg = match[7] ? arg.toExponential(match[7]) : arg.toExponential(); break;\r
1648           case 'f': arg = match[7] ? parseFloat(arg).toFixed(match[7]) : parseFloat(arg); break;\r
1649           case 'o': arg = arg.toString(8); break;\r
1650           case 's': arg = ((arg = String(arg)) && match[7] ? arg.substring(0, match[7]) : arg); break;\r
1651           case 'u': arg = Math.abs(arg); break;\r
1652           case 'x': arg = arg.toString(16); break;\r
1653           case 'X': arg = arg.toString(16).toUpperCase(); break;\r
1654         }\r
1655         arg = (/[def]/.test(match[8]) && match[3] && arg >= 0 ? '+'+ arg : arg);\r
1656         pad_character = match[4] ? match[4] == '0' ? '0' : match[4].charAt(1) : ' ';\r
1657         pad_length = match[6] - String(arg).length;\r
1658         pad = match[6] ? str_repeat(pad_character, pad_length) : '';\r
1659         output.push(match[5] ? arg + pad : pad + arg);\r
1660       }\r
1661     }\r
1662     return output.join('');\r
1663   };\r
1664 \r
1665   str_format.cache = {};\r
1666 \r
1667   str_format.parse = function(fmt) {\r
1668     var _fmt = fmt, match = [], parse_tree = [], arg_names = 0;\r
1669     while (_fmt) {\r
1670       if ((match = /^[^\x25]+/.exec(_fmt)) !== null) {\r
1671         parse_tree.push(match[0]);\r
1672       }\r
1673       else if ((match = /^\x25{2}/.exec(_fmt)) !== null) {\r
1674         parse_tree.push('%');\r
1675       }\r
1676       else if ((match = /^\x25(?:([1-9]\d*)\$|\(([^\)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(_fmt)) !== null) {\r
1677         if (match[2]) {\r
1678           arg_names |= 1;\r
1679           var field_list = [], replacement_field = match[2], field_match = [];\r
1680           if ((field_match = /^([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) {\r
1681             field_list.push(field_match[1]);\r
1682             while ((replacement_field = replacement_field.substring(field_match[0].length)) !== '') {\r
1683               if ((field_match = /^\.([a-z_][a-z_\d]*)/i.exec(replacement_field)) !== null) {\r
1684                 field_list.push(field_match[1]);\r
1685               }\r
1686               else if ((field_match = /^\[(\d+)\]/.exec(replacement_field)) !== null) {\r
1687                 field_list.push(field_match[1]);\r
1688               }\r
1689               else {\r
1690                 throw('[sprintf] huh?');\r
1691               }\r
1692             }\r
1693           }\r
1694           else {\r
1695             throw('[sprintf] huh?');\r
1696           }\r
1697           match[2] = field_list;\r
1698         }\r
1699         else {\r
1700           arg_names |= 2;\r
1701         }\r
1702         if (arg_names === 3) {\r
1703           throw('[sprintf] mixing positional and named placeholders is not (yet) supported');\r
1704         }\r
1705         parse_tree.push(match);\r
1706       }\r
1707       else {\r
1708         throw('[sprintf] huh?');\r
1709       }\r
1710       _fmt = _fmt.substring(match[0].length);\r
1711     }\r
1712     return parse_tree;\r
1713   };\r
1714 \r
1715   return str_format;\r
1716 })();\r
1717 \r
1718 var vsprintf = function(fmt, argv) {\r
1719   argv.unshift(fmt);\r
1720   return sprintf.apply(null, argv);\r
1721 };\r
1722 \r
1723 exports.sprintf = sprintf;\r
1724 exports.vsprintf = vsprintf;\r
1725 });\r
1726 \r
1727 require.define("/shred/response.js", function (require, module, exports, __dirname, __filename) {\r
1728     // The `Response object` encapsulates a Node.js HTTP response.\r
1729 \r
1730 var Content = require("./content")\r
1731   , HeaderMixins = require("./mixins/headers")\r
1732   , CookieJarLib = require( "cookiejar" )\r
1733   , Cookie = CookieJarLib.Cookie\r
1734 ;\r
1735 \r
1736 // Browser doesn't have zlib.\r
1737 var zlib = null;\r
1738 try {\r
1739   zlib = require('zlib');\r
1740 } catch (e) {\r
1741   // console.warn("no zlib library");\r
1742 }\r
1743 \r
1744 // Iconv doesn't work in browser\r
1745 var Iconv = null;\r
1746 try {\r
1747   Iconv = require('iconv-lite');\r
1748 } catch (e) {\r
1749   // console.warn("no iconv library");\r
1750 }\r
1751 \r
1752 // Construct a `Response` object. You should never have to do this directly. The\r
1753 // `Request` object handles this, getting the raw response object and passing it\r
1754 // in here, along with the request. The callback allows us to stream the response\r
1755 // and then use the callback to let the request know when it's ready.\r
1756 var Response = function(raw, request, callback) { \r
1757   var response = this;\r
1758   this._raw = raw;\r
1759 \r
1760   // The `._setHeaders` method is "private"; you can't otherwise set headers on\r
1761   // the response.\r
1762   this._setHeaders.call(this,raw.headers);\r
1763   \r
1764   // store any cookies\r
1765   if (request.cookieJar && this.getHeader('set-cookie')) {\r
1766     var cookieStrings = this.getHeader('set-cookie');\r
1767     var cookieObjs = []\r
1768       , cookie;\r
1769 \r
1770     for (var i = 0; i < cookieStrings.length; i++) {\r
1771       var cookieString = cookieStrings[i];\r
1772       if (!cookieString) {\r
1773         continue;\r
1774       }\r
1775 \r
1776       if (!cookieString.match(/domain\=/i)) {\r
1777         cookieString += '; domain=' + request.host;\r
1778       }\r
1779 \r
1780       if (!cookieString.match(/path\=/i)) {\r
1781         cookieString += '; path=' + request.path;\r
1782       }\r
1783 \r
1784       try {\r
1785         cookie = new Cookie(cookieString);\r
1786         if (cookie) {\r
1787           cookieObjs.push(cookie);\r
1788         }\r
1789       } catch (e) {\r
1790         console.warn("Tried to set bad cookie: " + cookieString);\r
1791       }\r
1792     }\r
1793 \r
1794     request.cookieJar.setCookies(cookieObjs);\r
1795   }\r
1796 \r
1797   this.request = request;\r
1798   this.client = request.client;\r
1799   this.log = this.request.log;\r
1800 \r
1801   // Stream the response content entity and fire the callback when we're done.\r
1802   // Store the incoming data in a array of Buffers which we concatinate into one\r
1803   // buffer at the end.  We need to use buffers instead of strings here in order\r
1804   // to preserve binary data.\r
1805   var chunkBuffers = [];\r
1806   var dataLength = 0;\r
1807   raw.on("data", function(chunk) {\r
1808     chunkBuffers.push(chunk);\r
1809     dataLength += chunk.length;\r
1810   });\r
1811   raw.on("end", function() {\r
1812     var body;\r
1813     if (typeof Buffer === 'undefined') {\r
1814       // Just concatinate into a string\r
1815       body = chunkBuffers.join('');\r
1816     } else {\r
1817       // Initialize new buffer and add the chunks one-at-a-time.\r
1818       body = new Buffer(dataLength);\r
1819       for (var i = 0, pos = 0; i < chunkBuffers.length; i++) {\r
1820         chunkBuffers[i].copy(body, pos);\r
1821         pos += chunkBuffers[i].length;\r
1822       }\r
1823     }\r
1824 \r
1825     var setBodyAndFinish = function (body) {\r
1826       response._body = new Content({ \r
1827         body: body,\r
1828         type: response.getHeader("Content-Type")\r
1829       });\r
1830       callback(response);\r
1831     }\r
1832 \r
1833     if (zlib && response.getHeader("Content-Encoding") === 'gzip'){\r
1834       zlib.gunzip(body, function (err, gunzippedBody) {\r
1835         if (Iconv && response.request.encoding){\r
1836           body = Iconv.fromEncoding(gunzippedBody,response.request.encoding);\r
1837         } else {\r
1838           body = gunzippedBody.toString();\r
1839         }\r
1840         setBodyAndFinish(body);\r
1841       })\r
1842     }\r
1843     else{\r
1844        if (response.request.encoding){\r
1845             body = Iconv.fromEncoding(body,response.request.encoding);\r
1846         }        \r
1847       setBodyAndFinish(body);\r
1848     }\r
1849   });\r
1850 };\r
1851 \r
1852 // The `Response` object can be pretty overwhelming to view using the built-in\r
1853 // Node.js inspect method. We want to make it a bit more manageable. This\r
1854 // probably goes [too far in the other\r
1855 // direction](https://github.com/spire-io/shred/issues/2).\r
1856 \r
1857 Response.prototype = {\r
1858   inspect: function() {\r
1859     var response = this;\r
1860     var headers = this.format_headers();\r
1861     var summary = ["<Shred Response> ", response.status].join(" ")\r
1862     return [ summary, "- Headers:", headers].join("\n");\r
1863   },\r
1864   format_headers: function () {\r
1865     var array = []\r
1866     var headers = this._headers\r
1867     for (var key in headers) {\r
1868       if (headers.hasOwnProperty(key)) {\r
1869         var value = headers[key]\r
1870         array.push("\t" + key + ": " + value);\r
1871       }\r
1872     }\r
1873     return array.join("\n");\r
1874   }\r
1875 };\r
1876 \r
1877 // `Response` object properties, all of which are read-only:\r
1878 Object.defineProperties(Response.prototype, {\r
1879   \r
1880 // - **status**. The HTTP status code for the response. \r
1881   status: {\r
1882     get: function() { return this._raw.statusCode; },\r
1883     enumerable: true\r
1884   },\r
1885 \r
1886 // - **content**. The HTTP content entity, if any. Provided as a [content\r
1887 //   object](./content.html), which will attempt to convert the entity based upon\r
1888 //   the `content-type` header. The converted value is available as\r
1889 //   `content.data`. The original raw content entity is available as\r
1890 //   `content.body`.\r
1891   body: {\r
1892     get: function() { return this._body; }\r
1893   },\r
1894   content: {\r
1895     get: function() { return this.body; },\r
1896     enumerable: true\r
1897   },\r
1898 \r
1899 // - **isRedirect**. Is the response a redirect? These are responses with 3xx\r
1900 //   status and a `Location` header.\r
1901   isRedirect: {\r
1902     get: function() {\r
1903       return (this.status>299\r
1904           &&this.status<400\r
1905           &&this.getHeader("Location"));\r
1906     },\r
1907     enumerable: true\r
1908   },\r
1909 \r
1910 // - **isError**. Is the response an error? These are responses with status of\r
1911 //   400 or greater.\r
1912   isError: {\r
1913     get: function() {\r
1914       return (this.status === 0 || this.status > 399)\r
1915     },\r
1916     enumerable: true\r
1917   }\r
1918 });\r
1919 \r
1920 // Add in the [getters for accessing the normalized headers](./headers.js).\r
1921 HeaderMixins.getters(Response);\r
1922 HeaderMixins.privateSetters(Response);\r
1923 \r
1924 // Work around Mozilla bug #608735 [https://bugzil.la/608735], which causes\r
1925 // getAllResponseHeaders() to return {} if the response is a CORS request.\r
1926 // xhr.getHeader still works correctly.\r
1927 var getHeader = Response.prototype.getHeader;\r
1928 Response.prototype.getHeader = function (name) {\r
1929   return (getHeader.call(this,name) ||\r
1930     (typeof this._raw.getHeader === 'function' && this._raw.getHeader(name)));\r
1931 };\r
1932 \r
1933 module.exports = Response;\r
1934 \r
1935 });\r
1936 \r
1937 require.define("/shred/content.js", function (require, module, exports, __dirname, __filename) {\r
1938     \r
1939 // The purpose of the `Content` object is to abstract away the data conversions\r
1940 // to and from raw content entities as strings. For example, you want to be able\r
1941 // to pass in a Javascript object and have it be automatically converted into a\r
1942 // JSON string if the `content-type` is set to a JSON-based media type.\r
1943 // Conversely, you want to be able to transparently get back a Javascript object\r
1944 // in the response if the `content-type` is a JSON-based media-type.\r
1945 \r
1946 // One limitation of the current implementation is that it [assumes the `charset` is UTF-8](https://github.com/spire-io/shred/issues/5).\r
1947 \r
1948 // The `Content` constructor takes an options object, which *must* have either a\r
1949 // `body` or `data` property and *may* have a `type` property indicating the\r
1950 // media type. If there is no `type` attribute, a default will be inferred.\r
1951 var Content = function(options) {\r
1952   this.body = options.body;\r
1953   this.data = options.data;\r
1954   this.type = options.type;\r
1955 };\r
1956 \r
1957 Content.prototype = {\r
1958   // Treat `toString()` as asking for the `content.body`. That is, the raw content entity.\r
1959   //\r
1960   //     toString: function() { return this.body; }\r
1961   //\r
1962   // Commented out, but I've forgotten why. :/\r
1963 };\r
1964 \r
1965 \r
1966 // `Content` objects have the following attributes:\r
1967 Object.defineProperties(Content.prototype,{\r
1968   \r
1969 // - **type**. Typically accessed as `content.type`, reflects the `content-type`\r
1970 //   header associated with the request or response. If not passed as an options\r
1971 //   to the constructor or set explicitly, it will infer the type the `data`\r
1972 //   attribute, if possible, and, failing that, will default to `text/plain`.\r
1973   type: {\r
1974     get: function() {\r
1975       if (this._type) {\r
1976         return this._type;\r
1977       } else {\r
1978         if (this._data) {\r
1979           switch(typeof this._data) {\r
1980             case "string": return "text/plain";\r
1981             case "object": return "application/json";\r
1982           }\r
1983         }\r
1984       }\r
1985       return "text/plain";\r
1986     },\r
1987     set: function(value) {\r
1988       this._type = value;\r
1989       return this;\r
1990     },\r
1991     enumerable: true\r
1992   },\r
1993 \r
1994 // - **data**. Typically accessed as `content.data`, reflects the content entity\r
1995 //   converted into Javascript data. This can be a string, if the `type` is, say,\r
1996 //   `text/plain`, but can also be a Javascript object. The conversion applied is\r
1997 //   based on the `processor` attribute. The `data` attribute can also be set\r
1998 //   directly, in which case the conversion will be done the other way, to infer\r
1999 //   the `body` attribute.\r
2000   data: {\r
2001     get: function() {\r
2002       if (this._body) {\r
2003         return this.processor.parser(this._body);\r
2004       } else {\r
2005         return this._data;\r
2006       }\r
2007     },\r
2008     set: function(data) {\r
2009       if (this._body&&data) Errors.setDataWithBody(this);\r
2010       this._data = data;\r
2011       return this;\r
2012     },\r
2013     enumerable: true\r
2014   },\r
2015 \r
2016 // - **body**. Typically accessed as `content.body`, reflects the content entity\r
2017 //   as a UTF-8 string. It is the mirror of the `data` attribute. If you set the\r
2018 //   `data` attribute, the `body` attribute will be inferred and vice-versa. If\r
2019 //   you attempt to set both, an exception is raised.\r
2020   body: {\r
2021     get: function() {\r
2022       if (this._data) {\r
2023         return this.processor.stringify(this._data);\r
2024       } else {\r
2025         return this.processor.stringify(this._body);\r
2026       }\r
2027     },\r
2028     set: function(body) {\r
2029       if (this._data&&body) Errors.setBodyWithData(this);\r
2030       this._body = body;\r
2031       return this;\r
2032     },\r
2033     enumerable: true\r
2034   },\r
2035 \r
2036 // - **processor**. The functions that will be used to convert to/from `data` and\r
2037 //   `body` attributes. You can add processors. The two that are built-in are for\r
2038 //   `text/plain`, which is basically an identity transformation and\r
2039 //   `application/json` and other JSON-based media types (including custom media\r
2040 //   types with `+json`). You can add your own processors. See below.\r
2041   processor: {\r
2042     get: function() {\r
2043       var processor = Content.processors[this.type];\r
2044       if (processor) {\r
2045         return processor;\r
2046       } else {\r
2047         // Return the first processor that matches any part of the\r
2048         // content type. ex: application/vnd.foobar.baz+json will match json.\r
2049         var main = this.type.split(";")[0];\r
2050         var parts = main.split(/\+|\//);\r
2051         for (var i=0, l=parts.length; i < l; i++) {\r
2052           processor = Content.processors[parts[i]]\r
2053         }\r
2054         return processor || {parser:identity,stringify:toString};\r
2055       }\r
2056     },\r
2057     enumerable: true\r
2058   },\r
2059 \r
2060 // - **length**. Typically accessed as `content.length`, returns the length in\r
2061 //   bytes of the raw content entity.\r
2062   length: {\r
2063     get: function() {\r
2064       if (typeof Buffer !== 'undefined') {\r
2065         return Buffer.byteLength(this.body);\r
2066       }\r
2067       return this.body.length;\r
2068     }\r
2069   }\r
2070 });\r
2071 \r
2072 Content.processors = {};\r
2073 \r
2074 // The `registerProcessor` function allows you to add your own processors to\r
2075 // convert content entities. Each processor consists of a Javascript object with\r
2076 // two properties:\r
2077 // - **parser**. The function used to parse a raw content entity and convert it\r
2078 //   into a Javascript data type.\r
2079 // - **stringify**. The function used to convert a Javascript data type into a\r
2080 //   raw content entity.\r
2081 Content.registerProcessor = function(types,processor) {\r
2082   \r
2083 // You can pass an array of types that will trigger this processor, or just one.\r
2084 // We determine the array via duck-typing here.\r
2085   if (types.forEach) {\r
2086     types.forEach(function(type) {\r
2087       Content.processors[type] = processor;\r
2088     });\r
2089   } else {\r
2090     // If you didn't pass an array, we just use what you pass in.\r
2091     Content.processors[types] = processor;\r
2092   }\r
2093 };\r
2094 \r
2095 // Register the identity processor, which is used for text-based media types.\r
2096 var identity = function(x) { return x; }\r
2097   , toString = function(x) { return x.toString(); }\r
2098 Content.registerProcessor(\r
2099   ["text/html","text/plain","text"],\r
2100   { parser: identity, stringify: toString });\r
2101 \r
2102 // Register the JSON processor, which is used for JSON-based media types.\r
2103 Content.registerProcessor(\r
2104   ["application/json; charset=utf-8","application/json","json"],\r
2105   {\r
2106     parser: function(string) {\r
2107       return JSON.parse(string);\r
2108     },\r
2109     stringify: function(data) {\r
2110       return JSON.stringify(data); }});\r
2111 \r
2112 // Error functions are defined separately here in an attempt to make the code\r
2113 // easier to read.\r
2114 var Errors = {\r
2115   setDataWithBody: function(object) {\r
2116     throw new Error("Attempt to set data attribute of a content object " +\r
2117         "when the body attributes was already set.");\r
2118   },\r
2119   setBodyWithData: function(object) {\r
2120     throw new Error("Attempt to set body attribute of a content object " +\r
2121         "when the data attributes was already set.");\r
2122   }\r
2123 }\r
2124 module.exports = Content;\r
2125 \r
2126 });\r
2127 \r
2128 require.define("/shred/mixins/headers.js", function (require, module, exports, __dirname, __filename) {\r
2129     // The header mixins allow you to add HTTP header support to any object. This\r
2130 // might seem pointless: why not simply use a hash? The main reason is that, per\r
2131 // the [HTTP spec](http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2),\r
2132 // headers are case-insensitive. So, for example, `content-type` is the same as\r
2133 // `CONTENT-TYPE` which is the same as `Content-Type`. Since there is no way to\r
2134 // overload the index operator in Javascript, using a hash to represent the\r
2135 // headers means it's possible to have two conflicting values for a single\r
2136 // header.\r
2137 // \r
2138 // The solution to this is to provide explicit methods to set or get headers.\r
2139 // This also has the benefit of allowing us to introduce additional variations,\r
2140 // including snake case, which we automatically convert to what Matthew King has\r
2141 // dubbed "corset case" - the hyphen-separated names with initial caps:\r
2142 // `Content-Type`. We use corset-case just in case we're dealing with servers\r
2143 // that haven't properly implemented the spec.\r
2144 \r
2145 // Convert headers to corset-case. **Example:** `CONTENT-TYPE` will be converted\r
2146 // to `Content-Type`.\r
2147 \r
2148 var corsetCase = function(string) {\r
2149   return string;//.toLowerCase()\r
2150       //.replace("_","-")\r
2151       // .replace(/(^|-)(\w)/g, \r
2152           // function(s) { return s.toUpperCase(); });\r
2153 };\r
2154 \r
2155 // We suspect that `initializeHeaders` was once more complicated ...\r
2156 var initializeHeaders = function(object) {\r
2157   return {};\r
2158 };\r
2159 \r
2160 // Access the `_headers` property using lazy initialization. **Warning:** If you\r
2161 // mix this into an object that is using the `_headers` property already, you're\r
2162 // going to have trouble.\r
2163 var $H = function(object) {\r
2164   return object._headers||(object._headers=initializeHeaders(object));\r
2165 };\r
2166 \r
2167 // Hide the implementations as private functions, separate from how we expose them.\r
2168 \r
2169 // The "real" `getHeader` function: get the header after normalizing the name.\r
2170 var getHeader = function(object,name) {\r
2171   return $H(object)[corsetCase(name)];\r
2172 };\r
2173 \r
2174 // The "real" `getHeader` function: get one or more headers, or all of them\r
2175 // if you don't ask for any specifics. \r
2176 var getHeaders = function(object,names) {\r
2177   var keys = (names && names.length>0) ? names : Object.keys($H(object));\r
2178   var hash = keys.reduce(function(hash,key) {\r
2179     hash[key] = getHeader(object,key);\r
2180     return hash;\r
2181   },{});\r
2182   // Freeze the resulting hash so you don't mistakenly think you're modifying\r
2183   // the real headers.\r
2184   Object.freeze(hash);\r
2185   return hash;\r
2186 };\r
2187 \r
2188 // The "real" `setHeader` function: set a header, after normalizing the name.\r
2189 var setHeader = function(object,name,value) {\r
2190   $H(object)[corsetCase(name)] = value;\r
2191   return object;\r
2192 };\r
2193 \r
2194 // The "real" `setHeaders` function: set multiple headers based on a hash.\r
2195 var setHeaders = function(object,hash) {\r
2196   for( var key in hash ) { setHeader(object,key,hash[key]); };\r
2197   return this;\r
2198 };\r
2199 \r
2200 // Here's where we actually bind the functionality to an object. These mixins work by\r
2201 // exposing mixin functions. Each function mixes in a specific batch of features.\r
2202 module.exports = {\r
2203   \r
2204   // Add getters.\r
2205   getters: function(constructor) {\r
2206     constructor.prototype.getHeader = function(name) { return getHeader(this,name); };\r
2207     constructor.prototype.getHeaders = function() { return getHeaders(this,arguments); };\r
2208   },\r
2209   // Add setters but as "private" methods.\r
2210   privateSetters: function(constructor) {\r
2211     constructor.prototype._setHeader = function(key,value) { return setHeader(this,key,value); };\r
2212     constructor.prototype._setHeaders = function(hash) { return setHeaders(this,hash); };\r
2213   },\r
2214   // Add setters.\r
2215   setters: function(constructor) {\r
2216     constructor.prototype.setHeader = function(key,value) { return setHeader(this,key,value); };\r
2217     constructor.prototype.setHeaders = function(hash) { return setHeaders(this,hash); };\r
2218   },\r
2219   // Add both getters and setters.\r
2220   gettersAndSetters: function(constructor) {\r
2221     constructor.prototype.getHeader = function(name) { return getHeader(this,name); };\r
2222     constructor.prototype.getHeaders = function() { return getHeaders(this,arguments); };\r
2223     constructor.prototype.setHeader = function(key,value) { return setHeader(this,key,value); };\r
2224     constructor.prototype.setHeaders = function(hash) { return setHeaders(this,hash); };\r
2225   }\r
2226 };\r
2227 \r
2228 });\r
2229 \r
2230 require.define("/node_modules/iconv-lite/package.json", function (require, module, exports, __dirname, __filename) {\r
2231     module.exports = {}\r
2232 });\r
2233 \r
2234 require.define("/node_modules/iconv-lite/index.js", function (require, module, exports, __dirname, __filename) {\r
2235     // Module exports\r
2236 var iconv = module.exports = {\r
2237     toEncoding: function(str, encoding) {\r
2238         return iconv.getCodec(encoding).toEncoding(str);\r
2239     },\r
2240     fromEncoding: function(buf, encoding) {\r
2241         return iconv.getCodec(encoding).fromEncoding(buf);\r
2242     },\r
2243     \r
2244     defaultCharUnicode: '�',\r
2245     defaultCharSingleByte: '?',\r
2246     \r
2247     // Get correct codec for given encoding.\r
2248     getCodec: function(encoding) {\r
2249         var enc = encoding || "utf8";\r
2250         var codecOptions = undefined;\r
2251         while (1) {\r
2252             if (getType(enc) === "String")\r
2253                 enc = enc.replace(/[- ]/g, "").toLowerCase();\r
2254             var codec = iconv.encodings[enc];\r
2255             var type = getType(codec);\r
2256             if (type === "String") {\r
2257                 // Link to other encoding.\r
2258                 codecOptions = {originalEncoding: enc};\r
2259                 enc = codec;\r
2260             }\r
2261             else if (type === "Object" && codec.type != undefined) {\r
2262                 // Options for other encoding.\r
2263                 codecOptions = codec;\r
2264                 enc = codec.type;\r
2265             } \r
2266             else if (type === "Function")\r
2267                 // Codec itself.\r
2268                 return codec(codecOptions);\r
2269             else\r
2270                 throw new Error("Encoding not recognized: '" + encoding + "' (searched as: '"+enc+"')");\r
2271         }\r
2272     },\r
2273     \r
2274     // Define basic encodings\r
2275     encodings: {\r
2276         internal: function(options) {\r
2277             return {\r
2278                 toEncoding: function(str) {\r
2279                     return new Buffer(ensureString(str), options.originalEncoding);\r
2280                 },\r
2281                 fromEncoding: function(buf) {\r
2282                     return ensureBuffer(buf).toString(options.originalEncoding);\r
2283                 }\r
2284             };\r
2285         },\r
2286         utf8: "internal",\r
2287         ucs2: "internal",\r
2288         binary: "internal",\r
2289         ascii: "internal",\r
2290         base64: "internal",\r
2291         \r
2292         // Codepage single-byte encodings.\r
2293         singlebyte: function(options) {\r
2294             // Prepare chars if needed\r
2295             if (!options.chars || (options.chars.length !== 128 && options.chars.length !== 256))\r
2296                 throw new Error("Encoding '"+options.type+"' has incorrect 'chars' (must be of len 128 or 256)");\r
2297             \r
2298             if (options.chars.length === 128)\r
2299                 options.chars = asciiString + options.chars;\r
2300             \r
2301             if (!options.charsBuf) {\r
2302                 options.charsBuf = new Buffer(options.chars, 'ucs2');\r
2303             }\r
2304             \r
2305             if (!options.revCharsBuf) {\r
2306                 options.revCharsBuf = new Buffer(65536);\r
2307                 var defChar = iconv.defaultCharSingleByte.charCodeAt(0);\r
2308                 for (var i = 0; i < options.revCharsBuf.length; i++)\r
2309                     options.revCharsBuf[i] = defChar;\r
2310                 for (var i = 0; i < options.chars.length; i++)\r
2311                     options.revCharsBuf[options.chars.charCodeAt(i)] = i;\r
2312             }\r
2313             \r
2314             return {\r
2315                 toEncoding: function(str) {\r
2316                     str = ensureString(str);\r
2317                     \r
2318                     var buf = new Buffer(str.length);\r
2319                     var revCharsBuf = options.revCharsBuf;\r
2320                     for (var i = 0; i < str.length; i++)\r
2321                         buf[i] = revCharsBuf[str.charCodeAt(i)];\r
2322                     \r
2323                     return buf;\r
2324                 },\r
2325                 fromEncoding: function(buf) {\r
2326                     buf = ensureBuffer(buf);\r
2327                     \r
2328                     // Strings are immutable in JS -> we use ucs2 buffer to speed up computations.\r
2329                     var charsBuf = options.charsBuf;\r
2330                     var newBuf = new Buffer(buf.length*2);\r
2331                     var idx1 = 0, idx2 = 0;\r
2332                     for (var i = 0, _len = buf.length; i < _len; i++) {\r
2333                         idx1 = buf[i]*2; idx2 = i*2;\r
2334                         newBuf[idx2] = charsBuf[idx1];\r
2335                         newBuf[idx2+1] = charsBuf[idx1+1];\r
2336                     }\r
2337                     return newBuf.toString('ucs2');\r
2338                 }\r
2339             };\r
2340         },\r
2341 \r
2342         // Codepage double-byte encodings.\r
2343         table: function(options) {\r
2344             var table = options.table, key, revCharsTable = options.revCharsTable;\r
2345             if (!table) {\r
2346                 throw new Error("Encoding '" + options.type +"' has incorect 'table' option");\r
2347             }\r
2348             if(!revCharsTable) {\r
2349                 revCharsTable = options.revCharsTable = {};\r
2350                 for (key in table) {\r
2351                     revCharsTable[table[key]] = parseInt(key);\r
2352                 }\r
2353             }\r
2354             \r
2355             return {\r
2356                 toEncoding: function(str) {\r
2357                     str = ensureString(str);\r
2358                     var strLen = str.length;\r
2359                     var bufLen = strLen;\r
2360                     for (var i = 0; i < strLen; i++)\r
2361                         if (str.charCodeAt(i) >> 7)\r
2362                             bufLen++;\r
2363 \r
2364                     var newBuf = new Buffer(bufLen), gbkcode, unicode, \r
2365                         defaultChar = revCharsTable[iconv.defaultCharUnicode.charCodeAt(0)];\r
2366 \r
2367                     for (var i = 0, j = 0; i < strLen; i++) {\r
2368                         unicode = str.charCodeAt(i);\r
2369                         if (unicode >> 7) {\r
2370                             gbkcode = revCharsTable[unicode] || defaultChar;\r
2371                             newBuf[j++] = gbkcode >> 8; //high byte;\r
2372                             newBuf[j++] = gbkcode & 0xFF; //low byte\r
2373                         } else {//ascii\r
2374                             newBuf[j++] = unicode;\r
2375                         }\r
2376                     }\r
2377                     return newBuf;\r
2378                 },\r
2379                 fromEncoding: function(buf) {\r
2380                     buf = ensureBuffer(buf);\r
2381                     var bufLen = buf.length, strLen = 0;\r
2382                     for (var i = 0; i < bufLen; i++) {\r
2383                         strLen++;\r
2384                         if (buf[i] & 0x80) //the high bit is 1, so this byte is gbkcode's high byte.skip next byte\r
2385                             i++;\r
2386                     }\r
2387                     var newBuf = new Buffer(strLen*2), unicode, gbkcode,\r
2388                         defaultChar = iconv.defaultCharUnicode.charCodeAt(0);\r
2389                     \r
2390                     for (var i = 0, j = 0; i < bufLen; i++, j+=2) {\r
2391                         gbkcode = buf[i];\r
2392                         if (gbkcode & 0x80) {\r
2393                             gbkcode = (gbkcode << 8) + buf[++i];\r
2394                             unicode = table[gbkcode] || defaultChar;\r
2395                         } else {\r
2396                             unicode = gbkcode;\r
2397                         }\r
2398                         newBuf[j] = unicode & 0xFF; //low byte\r
2399                         newBuf[j+1] = unicode >> 8; //high byte\r
2400                     }\r
2401                     return newBuf.toString('ucs2');\r
2402                 }\r
2403             }\r
2404         }\r
2405     }\r
2406 };\r
2407 \r
2408 // Add aliases to convert functions\r
2409 iconv.encode = iconv.toEncoding;\r
2410 iconv.decode = iconv.fromEncoding;\r
2411 \r
2412 // Load other encodings from files in /encodings dir.\r
2413 var encodingsDir = __dirname+"/encodings/",\r
2414     fs = require('fs');\r
2415 fs.readdirSync(encodingsDir).forEach(function(file) {\r
2416     if(fs.statSync(encodingsDir + file).isDirectory()) return;\r
2417     var encodings = require(encodingsDir + file)\r
2418     for (var key in encodings)\r
2419         iconv.encodings[key] = encodings[key]\r
2420 });\r
2421 \r
2422 // Utilities\r
2423 var asciiString = '\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f'+\r
2424               ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f';\r
2425 \r
2426 var ensureBuffer = function(buf) {\r
2427     buf = buf || new Buffer(0);\r
2428     return (buf instanceof Buffer) ? buf : new Buffer(buf.toString(), "utf8");\r
2429 }\r
2430 \r
2431 var ensureString = function(str) {\r
2432     str = str || "";\r
2433     return (str instanceof String) ? str : str.toString((str instanceof Buffer) ? 'utf8' : undefined);\r
2434 }\r
2435 \r
2436 var getType = function(obj) {\r
2437     return Object.prototype.toString.call(obj).slice(8, -1);\r
2438 }\r
2439 \r
2440 \r
2441 });\r
2442 \r
2443 require.define("/node_modules/http-browserify/package.json", function (require, module, exports, __dirname, __filename) {\r
2444     module.exports = {"main":"index.js","browserify":"browser.js"}\r
2445 });\r
2446 \r
2447 require.define("/node_modules/http-browserify/browser.js", function (require, module, exports, __dirname, __filename) {\r
2448     var http = module.exports;\r
2449 var EventEmitter = require('events').EventEmitter;\r
2450 var Request = require('./lib/request');\r
2451 \r
2452 http.request = function (params, cb) {\r
2453     if (!params) params = {};\r
2454     if (!params.host) params.host = window.location.host.split(':')[0];\r
2455     if (!params.port) params.port = window.location.port;\r
2456     \r
2457     var req = new Request(new xhrHttp, params);\r
2458     if (cb) req.on('response', cb);\r
2459     return req;\r
2460 };\r
2461 \r
2462 http.get = function (params, cb) {\r
2463     params.method = 'GET';\r
2464     var req = http.request(params, cb);\r
2465     req.end();\r
2466     return req;\r
2467 };\r
2468 \r
2469 var xhrHttp = (function () {\r
2470     if (typeof window === 'undefined') {\r
2471         throw new Error('no window object present');\r
2472     }\r
2473     else if (window.XMLHttpRequest) {\r
2474         return window.XMLHttpRequest;\r
2475     }\r
2476     else if (window.ActiveXObject) {\r
2477         var axs = [\r
2478             'Msxml2.XMLHTTP.6.0',\r
2479             'Msxml2.XMLHTTP.3.0',\r
2480             'Microsoft.XMLHTTP'\r
2481         ];\r
2482         for (var i = 0; i < axs.length; i++) {\r
2483             try {\r
2484                 var ax = new(window.ActiveXObject)(axs[i]);\r
2485                 return function () {\r
2486                     if (ax) {\r
2487                         var ax_ = ax;\r
2488                         ax = null;\r
2489                         return ax_;\r
2490                     }\r
2491                     else {\r
2492                         return new(window.ActiveXObject)(axs[i]);\r
2493                     }\r
2494                 };\r
2495             }\r
2496             catch (e) {}\r
2497         }\r
2498         throw new Error('ajax not supported in this browser')\r
2499     }\r
2500     else {\r
2501         throw new Error('ajax not supported in this browser');\r
2502     }\r
2503 })();\r
2504 \r
2505 http.STATUS_CODES = {\r
2506     100 : 'Continue',\r
2507     101 : 'Switching Protocols',\r
2508     102 : 'Processing', // RFC 2518, obsoleted by RFC 4918\r
2509     200 : 'OK',\r
2510     201 : 'Created',\r
2511     202 : 'Accepted',\r
2512     203 : 'Non-Authoritative Information',\r
2513     204 : 'No Content',\r
2514     205 : 'Reset Content',\r
2515     206 : 'Partial Content',\r
2516     207 : 'Multi-Status', // RFC 4918\r
2517     300 : 'Multiple Choices',\r
2518     301 : 'Moved Permanently',\r
2519     302 : 'Moved Temporarily',\r
2520     303 : 'See Other',\r
2521     304 : 'Not Modified',\r
2522     305 : 'Use Proxy',\r
2523     307 : 'Temporary Redirect',\r
2524     400 : 'Bad Request',\r
2525     401 : 'Unauthorized',\r
2526     402 : 'Payment Required',\r
2527     403 : 'Forbidden',\r
2528     404 : 'Not Found',\r
2529     405 : 'Method Not Allowed',\r
2530     406 : 'Not Acceptable',\r
2531     407 : 'Proxy Authentication Required',\r
2532     408 : 'Request Time-out',\r
2533     409 : 'Conflict',\r
2534     410 : 'Gone',\r
2535     411 : 'Length Required',\r
2536     412 : 'Precondition Failed',\r
2537     413 : 'Request Entity Too Large',\r
2538     414 : 'Request-URI Too Large',\r
2539     415 : 'Unsupported Media Type',\r
2540     416 : 'Requested Range Not Satisfiable',\r
2541     417 : 'Expectation Failed',\r
2542     418 : 'I\'m a teapot', // RFC 2324\r
2543     422 : 'Unprocessable Entity', // RFC 4918\r
2544     423 : 'Locked', // RFC 4918\r
2545     424 : 'Failed Dependency', // RFC 4918\r
2546     425 : 'Unordered Collection', // RFC 4918\r
2547     426 : 'Upgrade Required', // RFC 2817\r
2548     500 : 'Internal Server Error',\r
2549     501 : 'Not Implemented',\r
2550     502 : 'Bad Gateway',\r
2551     503 : 'Service Unavailable',\r
2552     504 : 'Gateway Time-out',\r
2553     505 : 'HTTP Version not supported',\r
2554     506 : 'Variant Also Negotiates', // RFC 2295\r
2555     507 : 'Insufficient Storage', // RFC 4918\r
2556     509 : 'Bandwidth Limit Exceeded',\r
2557     510 : 'Not Extended' // RFC 2774\r
2558 };\r
2559 \r
2560 });\r
2561 \r
2562 require.define("/node_modules/http-browserify/lib/request.js", function (require, module, exports, __dirname, __filename) {\r
2563     var EventEmitter = require('events').EventEmitter;\r
2564 var Response = require('./response');\r
2565 var isSafeHeader = require('./isSafeHeader');\r
2566 \r
2567 var Request = module.exports = function (xhr, params) {\r
2568     var self = this;\r
2569     self.xhr = xhr;\r
2570     self.body = '';\r
2571     \r
2572     var uri = params.host + ':' + params.port + (params.path || '/');\r
2573     \r
2574     xhr.open(\r
2575         params.method || 'GET',\r
2576         (params.scheme || 'http') + '://' + uri,\r
2577         true\r
2578     );\r
2579     \r
2580     if (params.headers) {\r
2581         Object.keys(params.headers).forEach(function (key) {\r
2582             if (!isSafeHeader(key)) return;\r
2583             var value = params.headers[key];\r
2584             if (Array.isArray(value)) {\r
2585                 value.forEach(function (v) {\r
2586                     xhr.setRequestHeader(key, v);\r
2587                 });\r
2588             }\r
2589             else xhr.setRequestHeader(key, value)\r
2590         });\r
2591     }\r
2592     \r
2593     var res = new Response(xhr);\r
2594     res.on('ready', function () {\r
2595         self.emit('response', res);\r
2596     });\r
2597     \r
2598     xhr.onreadystatechange = function () {\r
2599         res.handle(xhr);\r
2600     };\r
2601 };\r
2602 \r
2603 Request.prototype = new EventEmitter;\r
2604 \r
2605 Request.prototype.setHeader = function (key, value) {\r
2606     if ((Array.isArray && Array.isArray(value))\r
2607     || value instanceof Array) {\r
2608         for (var i = 0; i < value.length; i++) {\r
2609             this.xhr.setRequestHeader(key, value[i]);\r
2610         }\r
2611     }\r
2612     else {\r
2613         this.xhr.setRequestHeader(key, value);\r
2614     }\r
2615 };\r
2616 \r
2617 Request.prototype.write = function (s) {\r
2618     this.body += s;\r
2619 };\r
2620 \r
2621 Request.prototype.end = function (s) {\r
2622     if (s !== undefined) this.write(s);\r
2623     this.xhr.send(this.body);\r
2624 };\r
2625 \r
2626 });\r
2627 \r
2628 require.define("/node_modules/http-browserify/lib/response.js", function (require, module, exports, __dirname, __filename) {\r
2629     var EventEmitter = require('events').EventEmitter;\r
2630 var isSafeHeader = require('./isSafeHeader');\r
2631 \r
2632 var Response = module.exports = function (xhr) {\r
2633     this.xhr = xhr;\r
2634     this.offset = 0;\r
2635 };\r
2636 \r
2637 Response.prototype = new EventEmitter;\r
2638 \r
2639 var capable = {\r
2640     streaming : true,\r
2641     status2 : true\r
2642 };\r
2643 \r
2644 function parseHeaders (xhr) {\r
2645     var lines = xhr.getAllResponseHeaders().split(/\r?\n/);\r
2646     var headers = {};\r
2647     for (var i = 0; i < lines.length; i++) {\r
2648         var line = lines[i];\r
2649         if (line === '') continue;\r
2650         \r
2651         var m = line.match(/^([^:]+):\s*(.*)/);\r
2652         if (m) {\r
2653             var key = m[1].toLowerCase(), value = m[2];\r
2654             \r
2655             if (headers[key] !== undefined) {\r
2656                 if ((Array.isArray && Array.isArray(headers[key]))\r
2657                 || headers[key] instanceof Array) {\r
2658                     headers[key].push(value);\r
2659                 }\r
2660                 else {\r
2661                     headers[key] = [ headers[key], value ];\r
2662                 }\r
2663             }\r
2664             else {\r
2665                 headers[key] = value;\r
2666             }\r
2667         }\r
2668         else {\r
2669             headers[line] = true;\r
2670         }\r
2671     }\r
2672     return headers;\r
2673 }\r
2674 \r
2675 Response.prototype.getHeader = function (key) {\r
2676     var header = this.headers ? this.headers[key.toLowerCase()] : null;\r
2677     if (header) return header;\r
2678 \r
2679     // Work around Mozilla bug #608735 [https://bugzil.la/608735], which causes\r
2680     // getAllResponseHeaders() to return {} if the response is a CORS request.\r
2681     // xhr.getHeader still works correctly.\r
2682     if (isSafeHeader(key)) {\r
2683       return this.xhr.getResponseHeader(key);\r
2684     }\r
2685     return null;\r
2686 };\r
2687 \r
2688 Response.prototype.handle = function () {\r
2689     var xhr = this.xhr;\r
2690     if (xhr.readyState === 2 && capable.status2) {\r
2691         try {\r
2692             this.statusCode = xhr.status;\r
2693             this.headers = parseHeaders(xhr);\r
2694         }\r
2695         catch (err) {\r
2696             capable.status2 = false;\r
2697         }\r
2698         \r
2699         if (capable.status2) {\r
2700             this.emit('ready');\r
2701         }\r
2702     }\r
2703     else if (capable.streaming && xhr.readyState === 3) {\r
2704         try {\r
2705             if (!this.statusCode) {\r
2706                 this.statusCode = xhr.status;\r
2707                 this.headers = parseHeaders(xhr);\r
2708                 this.emit('ready');\r
2709             }\r
2710         }\r
2711         catch (err) {}\r
2712         \r
2713         try {\r
2714             this.write();\r
2715         }\r
2716         catch (err) {\r
2717             capable.streaming = false;\r
2718         }\r
2719     }\r
2720     else if (xhr.readyState === 4) {\r
2721         if (!this.statusCode) {\r
2722             this.statusCode = xhr.status;\r
2723             this.emit('ready');\r
2724         }\r
2725         this.write();\r
2726         \r
2727         if (xhr.error) {\r
2728             this.emit('error', xhr.responseText);\r
2729         }\r
2730         else this.emit('end');\r
2731     }\r
2732 };\r
2733 \r
2734 Response.prototype.write = function () {\r
2735     var xhr = this.xhr;\r
2736     if (xhr.responseText.length > this.offset) {\r
2737         this.emit('data', xhr.responseText.slice(this.offset));\r
2738         this.offset = xhr.responseText.length;\r
2739     }\r
2740 };\r
2741 \r
2742 });\r
2743 \r
2744 require.define("/node_modules/http-browserify/lib/isSafeHeader.js", function (require, module, exports, __dirname, __filename) {\r
2745     // Taken from http://dxr.mozilla.org/mozilla/mozilla-central/content/base/src/nsXMLHttpRequest.cpp.html\r
2746 var unsafeHeaders = [\r
2747     "accept-charset",\r
2748     "accept-encoding",\r
2749     "access-control-request-headers",\r
2750     "access-control-request-method",\r
2751     "connection",\r
2752     "content-length",\r
2753     "cookie",\r
2754     "cookie2",\r
2755     "content-transfer-encoding",\r
2756     "date",\r
2757     "expect",\r
2758     "host",\r
2759     "keep-alive",\r
2760     "origin",\r
2761     "referer",\r
2762     "set-cookie",\r
2763     "te",\r
2764     "trailer",\r
2765     "transfer-encoding",\r
2766     "upgrade",\r
2767     "user-agent",\r
2768     "via"\r
2769 ];\r
2770 \r
2771 module.exports = function (headerName) {\r
2772     if (!headerName) return false;\r
2773     return (unsafeHeaders.indexOf(headerName.toLowerCase()) === -1)\r
2774 };\r
2775 \r
2776 });\r
2777 \r
2778 require.alias("http-browserify", "/node_modules/http");\r
2779 \r
2780 require.alias("http-browserify", "/node_modules/https");