Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80536 views
1
// Copyright Joyent, Inc. and other Node contributors.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a
4
// copy of this software and associated documentation files (the
5
// "Software"), to deal in the Software without restriction, including
6
// without limitation the rights to use, copy, modify, merge, publish,
7
// distribute, sublicense, and/or sell copies of the Software, and to permit
8
// persons to whom the Software is furnished to do so, subject to the
9
// following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included
12
// in all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
// USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22
// test compression/decompression with dictionary
23
24
var common = require('../common.js');
25
var assert = require('assert');
26
var zlib = require('zlib');
27
var path = require('path');
28
29
var spdyDict = new Buffer([
30
'optionsgetheadpostputdeletetraceacceptaccept-charsetaccept-encodingaccept-',
31
'languageauthorizationexpectfromhostif-modified-sinceif-matchif-none-matchi',
32
'f-rangeif-unmodifiedsincemax-forwardsproxy-authorizationrangerefererteuser',
33
'-agent10010120020120220320420520630030130230330430530630740040140240340440',
34
'5406407408409410411412413414415416417500501502503504505accept-rangesageeta',
35
'glocationproxy-authenticatepublicretry-afterservervarywarningwww-authentic',
36
'ateallowcontent-basecontent-encodingcache-controlconnectiondatetrailertran',
37
'sfer-encodingupgradeviawarningcontent-languagecontent-lengthcontent-locati',
38
'oncontent-md5content-rangecontent-typeetagexpireslast-modifiedset-cookieMo',
39
'ndayTuesdayWednesdayThursdayFridaySaturdaySundayJanFebMarAprMayJunJulAugSe',
40
'pOctNovDecchunkedtext/htmlimage/pngimage/jpgimage/gifapplication/xmlapplic',
41
'ation/xhtmltext/plainpublicmax-agecharset=iso-8859-1utf-8gzipdeflateHTTP/1',
42
'.1statusversionurl\0'
43
].join(''));
44
45
var deflate = zlib.createDeflate({ dictionary: spdyDict });
46
47
var input = [
48
'HTTP/1.1 200 Ok',
49
'Server: node.js',
50
'Content-Length: 0',
51
''
52
].join('\r\n');
53
54
var called = 0;
55
56
//
57
// We'll use clean-new inflate stream each time
58
// and .reset() old dirty deflate one
59
//
60
function run(num) {
61
var inflate = zlib.createInflate({ dictionary: spdyDict });
62
63
if (num === 2) {
64
deflate.reset();
65
deflate.removeAllListeners('data');
66
}
67
68
// Put data into deflate stream
69
deflate.on('data', function(chunk) {
70
inflate.write(chunk);
71
});
72
73
// Get data from inflate stream
74
var output = [];
75
inflate.on('data', function(chunk) {
76
output.push(chunk);
77
});
78
inflate.on('end', function() {
79
called++;
80
81
assert.equal(output.join(''), input);
82
83
if (num < 2) run(num + 1);
84
});
85
86
deflate.write(input);
87
deflate.flush(function() {
88
inflate.end();
89
});
90
}
91
run(1);
92
93
process.on('exit', function() {
94
assert.equal(called, 2);
95
});
96
97