Skip to content

Commit

Permalink
fix: the server need use headersSent without use flushHeader (#4660)
Browse files Browse the repository at this point in the history
* fix: the server need use headersSent without use flushHeader

* fix: add new vars
  • Loading branch information
GiveMe-A-Name authored Sep 20, 2023
1 parent 14f95cf commit 411cea2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/moody-parents-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/prod-server': patch
---

fix(prod-server): the server need use headersSent without use flushHeader
fix(prod-server): 没有 flushHeader 时 server 应该使用 headersSent
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ export async function flushServerHeader({
}

res.flushHeaders();
res.modernFlushedHeaders = true;
}
6 changes: 5 additions & 1 deletion packages/server/prod-server/src/server/modernServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,11 @@ export class ModernServer implements ModernServerInterface {

private isSend(res: ServerResponse) {
/// Is true after response.end() has been called.
if (res.writableEnded) {
if (res.modernFlushedHeaders) {
if (res.writableFinished) {
return true;
}
} else if (res.headersSent) {
return true;
}

Expand Down
1 change: 1 addition & 0 deletions packages/server/prod-server/src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ declare module 'http' {

interface OutgoingMessage {
set: (key: string, value: any) => this;
modernFlushedHeaders?: boolean;
}
}

Expand Down

0 comments on commit 411cea2

Please sign in to comment.