|
| 1 | +// Flags: --experimental-quic --no-warnings |
| 2 | + |
| 3 | +// An incoming HTTP/3 request stream that is rejected without any |
| 4 | +// application processing (here, the session has no stream consumer) is |
| 5 | +// reset with H3_REQUEST_REJECTED (0x10b) so the peer learns the request |
| 6 | +// was not processed. See RFC 9114 section 4.1.1. |
| 7 | +// Refs: https://github.com/nodejs/node/issues/65441 |
| 8 | + |
| 9 | +import{hasQuic,skip,mustCall}from'../common/index.mjs'; |
| 10 | +importassertfrom'node:assert'; |
| 11 | +import*asfixturesfrom'../common/fixtures.mjs'; |
| 12 | + |
| 13 | +if(!hasQuic){ |
| 14 | +skip('QUIC is not enabled'); |
| 15 | +} |
| 16 | + |
| 17 | +const{ listen, connect }=awaitimport('node:quic'); |
| 18 | +const{ createPrivateKey }=awaitimport('node:crypto'); |
| 19 | + |
| 20 | +constkey=createPrivateKey(fixtures.readKey('agent1-key.pem')); |
| 21 | +constcert=fixtures.readKey('agent1-cert.pem'); |
| 22 | + |
| 23 | +// RFC 9114 H3_REQUEST_REJECTED. |
| 24 | +constH3_REQUEST_REJECTED=0x10bn; |
| 25 | + |
| 26 | +// The server registers no stream consumer, so an incoming request stream |
| 27 | +// is rejected on arrival. |
| 28 | +constserverEndpoint=awaitlisten(mustCall((serverSession)=>{ |
| 29 | +serverSession.onerror=()=>{}; |
| 30 | +}),{ |
| 31 | +sni: {'*': {keys: [key],certs: [cert]}}, |
| 32 | +}); |
| 33 | + |
| 34 | +constclientSession=awaitconnect(serverEndpoint.address,{ |
| 35 | +servername: 'localhost', |
| 36 | +verifyPeer: 'manual', |
| 37 | +}); |
| 38 | +awaitclientSession.opened; |
| 39 | + |
| 40 | +constreset=Promise.withResolvers(); |
| 41 | +conststream=awaitclientSession.createBidirectionalStream({ |
| 42 | +headers: { |
| 43 | +':method': 'GET', |
| 44 | +':path': '/test', |
| 45 | +':scheme': 'https', |
| 46 | +':authority': 'localhost', |
| 47 | +}, |
| 48 | +}); |
| 49 | +stream.onreset=mustCall((err)=>{ |
| 50 | +assert.strictEqual(err.code,'ERR_QUIC_APPLICATION_ERROR'); |
| 51 | +assert.strictEqual(err.errorCode,H3_REQUEST_REJECTED); |
| 52 | +reset.resolve(); |
| 53 | +}); |
| 54 | +awaitassert.rejects(stream.closed,{code: 'ERR_QUIC_APPLICATION_ERROR'}); |
| 55 | + |
| 56 | +awaitreset.promise; |
| 57 | +awaitclientSession.close(); |
| 58 | +awaitserverEndpoint.close(); |
0 commit comments