|
| 1 | +const expect = require('chai').expect, |
| 2 | + IS_NODE = typeof window === 'undefined'; |
| 3 | + |
| 4 | +(IS_NODE ? describe : describe.skip)('Requester Spec: maxHeaderSize', function () { |
| 5 | + let testrun, |
| 6 | + BASE_URL_HTTP1, |
| 7 | + BASE_URL_HTTP2; |
| 8 | + |
| 9 | + before(function (done) { |
| 10 | + BASE_URL_HTTP1 = global.servers.dynamicHeadersHTTP1; |
| 11 | + BASE_URL_HTTP2 = global.servers.dynamicHeadersHTTP2; |
| 12 | + done(); |
| 13 | + }); |
| 14 | + |
| 15 | + describe('HTTP/1: with maxHeaderSize: undefined (default)', function () { |
| 16 | + before(function (done) { |
| 17 | + this.run({ |
| 18 | + collection: { |
| 19 | + item: [{ |
| 20 | + request: { |
| 21 | + url: `${BASE_URL_HTTP1}/1024`, // 1KB |
| 22 | + method: 'GET' |
| 23 | + } |
| 24 | + }] |
| 25 | + } |
| 26 | + }, (err, results) => { |
| 27 | + testrun = results; |
| 28 | + done(err); |
| 29 | + }); |
| 30 | + }); |
| 31 | + |
| 32 | + it('should complete the request successfully', function () { |
| 33 | + expect(testrun).to.be.ok; |
| 34 | + const response = testrun.response.getCall(0).args[2]; |
| 35 | + |
| 36 | + expect(response).to.have.property('code', 200); // HTTP OK |
| 37 | + }); |
| 38 | + |
| 39 | + it('should include the correct number of headers', function () { |
| 40 | + const response = testrun.response.getCall(0).args[2]; |
| 41 | + |
| 42 | + expect(response.headers.count()).to.be.eql(5); |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + describe('HTTP/1: with maxHeaderSize: undefined and exceeded', function () { |
| 47 | + before(function (done) { |
| 48 | + this.run({ |
| 49 | + collection: { |
| 50 | + item: [{ |
| 51 | + request: { |
| 52 | + url: `${BASE_URL_HTTP1}/132000`, // > 128KB default set |
| 53 | + method: 'GET' |
| 54 | + } |
| 55 | + }] |
| 56 | + } |
| 57 | + }, (err, results) => { |
| 58 | + testrun = results; |
| 59 | + done(err); |
| 60 | + }); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should not complete the request and throw an error', function () { |
| 64 | + const error = testrun.request.getCall(0).args[0]; |
| 65 | + |
| 66 | + expect(error).to.be.ok; |
| 67 | + expect(error.code).to.eql('HPE_HEADER_OVERFLOW'); // Node.js error |
| 68 | + }); |
| 69 | + }); |
| 70 | + |
| 71 | + describe('HTTP/1: with maxHeaderSize: defined and exceeded', function () { |
| 72 | + const MAX_HEADER_SIZE = 512; |
| 73 | + |
| 74 | + before(function (done) { |
| 75 | + this.run({ |
| 76 | + collection: { |
| 77 | + item: [{ |
| 78 | + request: { |
| 79 | + url: `${BASE_URL_HTTP1}/600`, // Send 50 headers |
| 80 | + method: 'GET' |
| 81 | + } |
| 82 | + }] |
| 83 | + }, |
| 84 | + requester: { |
| 85 | + maxHeaderSize: MAX_HEADER_SIZE // Set a limit less than required to trigger failure |
| 86 | + } |
| 87 | + }, (err, results) => { |
| 88 | + testrun = results; |
| 89 | + done(err); |
| 90 | + }); |
| 91 | + }); |
| 92 | + |
| 93 | + it('should not complete the request and throw an error', function () { |
| 94 | + const error = testrun.request.getCall(0).args[0]; |
| 95 | + |
| 96 | + expect(error).to.be.ok; |
| 97 | + expect(error.code).to.eql('HPE_HEADER_OVERFLOW'); // Node.js error |
| 98 | + }); |
| 99 | + }); |
| 100 | + |
| 101 | + describe('HTTP/1: with maxHeaderSize: defined and respected', function () { |
| 102 | + const MAX_HEADER_SIZE = 8192; |
| 103 | + |
| 104 | + before(function (done) { |
| 105 | + this.run({ |
| 106 | + collection: { |
| 107 | + item: [{ |
| 108 | + request: { |
| 109 | + url: `${BASE_URL_HTTP1}/500`, // Send 10 headers |
| 110 | + method: 'GET' |
| 111 | + } |
| 112 | + }] |
| 113 | + }, |
| 114 | + requester: { |
| 115 | + maxHeaderSize: MAX_HEADER_SIZE // Set a limit more than required |
| 116 | + } |
| 117 | + }, (err, results) => { |
| 118 | + testrun = results; |
| 119 | + done(err); |
| 120 | + }); |
| 121 | + }); |
| 122 | + |
| 123 | + it('should complete the request successfully', function () { |
| 124 | + expect(testrun).to.be.ok; |
| 125 | + const response = testrun.response.getCall(0).args[2]; |
| 126 | + |
| 127 | + expect(response).to.have.property('code', 200); // HTTP OK |
| 128 | + }); |
| 129 | + |
| 130 | + it('should include the correct number of headers', function () { |
| 131 | + const response = testrun.response.getCall(0).args[2]; |
| 132 | + |
| 133 | + expect(response.headers.count()).to.be.eql(5); |
| 134 | + }); |
| 135 | + }); |
| 136 | + |
| 137 | + describe('HTTP/2: with maxHeaderSize: defined and exceeded (NO-OP)', function () { |
| 138 | + before(function (done) { |
| 139 | + this.run({ |
| 140 | + collection: { |
| 141 | + item: [{ |
| 142 | + request: { |
| 143 | + url: `${BASE_URL_HTTP2}/50`, // Send 50 headers |
| 144 | + method: 'GET' |
| 145 | + } |
| 146 | + }] |
| 147 | + }, |
| 148 | + requester: { |
| 149 | + strictSSL: false, |
| 150 | + protocolVersion: 'auto', |
| 151 | + maxHeaderSize: 10 // Set a limit less than required to trigger failure |
| 152 | + } |
| 153 | + }, (err, results) => { |
| 154 | + testrun = results; |
| 155 | + done(err); |
| 156 | + }); |
| 157 | + }); |
| 158 | + |
| 159 | + it('should include the correct number of headers', function () { |
| 160 | + const response = testrun.response.getCall(0).args[2]; |
| 161 | + |
| 162 | + expect(response.headers.count()).to.be.eql(3); |
| 163 | + }); |
| 164 | + }); |
| 165 | +}); |
0 commit comments