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