Skip to content

Commit

Permalink
fix(mitm): error reading destroyed from scoket
Browse files Browse the repository at this point in the history
  • Loading branch information
blakebyrnes committed Feb 8, 2021
1 parent 1d5906f commit f09e67f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions mitm/handlers/HttpRequestHandler.ts
Expand Up @@ -207,10 +207,9 @@ export default class HttpRequestHandler extends BaseHttpHandler {

context.setState(ResourceState.WriteProxyToClientResponseBody);

const http2Stream = (proxyToClientResponse as Http2ServerResponse).stream;
for await (const chunk of serverToProxyResponse) {
const data = context.cacheHandler.onResponseData(chunk as Buffer);
if (data && http2Stream?.destroyed !== true) {
if (data && !this.isClientConnectionDestroyed()) {
proxyToClientResponse.write(data, error => {
if (error && !this.isClientConnectionDestroyed())
this.onError('ServerToProxy.WriteResponseError', error);
Expand All @@ -219,7 +218,7 @@ export default class HttpRequestHandler extends BaseHttpHandler {
}

if (context.cacheHandler.shouldServeCachedData) {
if (proxyToClientResponse.socket.destroyed)
if (!this.isClientConnectionDestroyed())
proxyToClientResponse.write(context.cacheHandler.cacheData, error => {
if (error && !this.isClientConnectionDestroyed())
this.onError('ServerToProxy.WriteCachedResponseError', error);
Expand All @@ -242,7 +241,8 @@ export default class HttpRequestHandler extends BaseHttpHandler {
const proxyToClientResponse = this.context.proxyToClientResponse;
return (
(proxyToClientResponse as Http2ServerResponse).stream?.destroyed ||
proxyToClientResponse.socket?.destroyed
proxyToClientResponse.socket?.destroyed ||
proxyToClientResponse.connection?.destroyed
);
}

Expand Down

0 comments on commit f09e67f

Please sign in to comment.