Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: forward onRequestSent to handler #2375

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/core/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,14 @@ class Request {
if (channels.bodySent.hasSubscribers) {
channels.bodySent.publish({ request: this })
}

if (this[kHandler].onRequestSent) {
try {
this[kHandler].onRequestSent()
} catch (err) {
this.onError(err)
}
}
}

onConnect (abort) {
Expand Down
13 changes: 11 additions & 2 deletions test/client-dispatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,8 @@ test('dispatch onBodySent not a function', (t) => {
})

test('dispatch onBodySent buffer', (t) => {
t.plan(3)

const server = http.createServer((req, res) => {
res.end('ad')
})
Expand All @@ -688,20 +690,24 @@ test('dispatch onBodySent buffer', (t) => {
onBodySent (chunk) {
t.equal(chunk.toString(), body)
},
onRequestSent () {
t.pass()
},
onError (err) {
throw err
},
onConnect () {},
onHeaders () {},
onData () {},
onComplete () {
t.end()
t.pass()
}
})
})
})

test('dispatch onBodySent stream', (t) => {
t.plan(8)
const server = http.createServer((req, res) => {
res.end('ad')
})
Expand All @@ -723,6 +729,9 @@ test('dispatch onBodySent stream', (t) => {
t.equal(chunks[currentChunk++], chunk)
sentBytes += Buffer.byteLength(chunk)
},
onRequestSent () {
t.pass()
},
onError (err) {
throw err
},
Expand All @@ -732,7 +741,7 @@ test('dispatch onBodySent stream', (t) => {
onComplete () {
t.equal(currentChunk, chunks.length)
t.equal(sentBytes, toSendBytes)
t.end()
t.pass()
}
})
})
Expand Down