Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Apr 1, 2020
1 parent 7645711 commit d64298c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions source/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,8 @@ export default class Request extends Duplex implements RequestEvents<Request> {
this.push(null);
});

this.emit('response', response);

for (const destination of this[kServerResponsesPiped]) {
if (destination.headersSent) {
continue;
Expand All @@ -1119,8 +1121,6 @@ export default class Request extends Duplex implements RequestEvents<Request> {

destination.statusCode = statusCode;
}

this.emit('response', response);
}

_onRequest(request: ClientRequest): void {
Expand Down
17 changes: 16 additions & 1 deletion test/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,21 @@ test('errors have body', withServer, async (t, server, got) => {
})));

t.is(error.message, 'snap');
console.log(error.response);
t.is(error.response?.body, 'yay');
});

test('pipe can send modified headers', withServer, async (t, server, got) => {
server.get('/foobar', (_request, response) => {
response.setHeader('foo', 'bar');
response.end();
});

server.get('/', (_request, response) => {
got.stream('foobar').on('response', response => {
response.headers.foo = 'boo';
}).pipe(response);
});

const {headers} = await got('');
t.is(headers.foo, 'boo');
});

0 comments on commit d64298c

Please # to comment.