Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / socket.io / lib / transports / htmlfile.js
1
2 /*!
3  * socket.io-node
4  * Copyright(c) 2011 LearnBoost <dev@learnboost.com>
5  * MIT Licensed
6  */
7
8 /**
9  * Module requirements.
10  */
11
12 var HTTPTransport = require('./http');
13
14 /**
15  * Export the constructor.
16  */
17
18 exports = module.exports = HTMLFile;
19
20 /**
21  * HTMLFile transport constructor.
22  *
23  * @api public
24  */
25
26 function HTMLFile (mng, data, req) {
27   HTTPTransport.call(this, mng, data, req);
28 };
29
30 /**
31  * Inherits from Transport.
32  */
33
34 HTMLFile.prototype.__proto__ = HTTPTransport.prototype;
35
36 /**
37  * Transport name
38  *
39  * @api public
40  */
41
42 HTMLFile.prototype.name = 'htmlfile';
43
44 /**
45  * Handles the request.
46  *
47  * @api private
48  */
49
50 HTMLFile.prototype.handleRequest = function (req) {
51   HTTPTransport.prototype.handleRequest.call(this, req);
52
53   if (req.method == 'GET') {
54     req.res.writeHead(200, {
55         'Content-Type': 'text/html; charset=UTF-8'
56       , 'Connection': 'keep-alive'
57       , 'Transfer-Encoding': 'chunked'
58     });
59
60     req.res.write(
61         '<html><body>'
62       + '<script>var _ = function (msg) { parent.s._(msg, document); };</script>'
63       + new Array(174).join(' ')
64     );
65   }
66 };
67
68 /**
69  * Performs the write.
70  *
71  * @api private
72  */
73
74 HTMLFile.prototype.write = function (data) {
75   // escape all forward slashes. see GH-1251
76   data = '<script>_(' + JSON.stringify(data).replace(/\//g, '\\/') + ');</script>';
77
78   if (this.response.write(data)) {
79     this.drained = true;
80   }
81
82   this.log.debug(this.name + ' writing', data);
83 };