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

fix: all big enough ui proxy requests fail with error proxying with partial data #4266

Merged
merged 2 commits into from
Jul 24, 2020
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
4 changes: 4 additions & 0 deletions frontend/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { getIndexHTMLHandler } from './handlers/index-html';

import proxyMiddleware from './proxy-middleware';
import { Server } from 'http';
import { HACK_FIX_HPM_PARTIAL_RESPONSE_HEADERS } from './consts';

function getRegisterHandler(app: Application, basePath: string) {
return (
Expand Down Expand Up @@ -163,6 +164,7 @@ function createUIServer(options: UIConfigs) {
onProxyReq: proxyReq => {
console.log('Metadata proxied request: ', (proxyReq as any).path);
},
headers: HACK_FIX_HPM_PARTIAL_RESPONSE_HEADERS,
target: envoyServiceAddress,
}),
);
Expand Down Expand Up @@ -193,6 +195,7 @@ function createUIServer(options: UIConfigs) {
onProxyReq: proxyReq => {
console.log('Proxied request: ', proxyReq.path);
},
headers: HACK_FIX_HPM_PARTIAL_RESPONSE_HEADERS,
target: apiServerAddress,
}),
);
Expand All @@ -203,6 +206,7 @@ function createUIServer(options: UIConfigs) {
onProxyReq: proxyReq => {
console.log('Proxied request: ', proxyReq.path);
},
headers: HACK_FIX_HPM_PARTIAL_RESPONSE_HEADERS,
pathRewrite: pathStr =>
pathStr.startsWith(basePath) ? pathStr.substr(basePath.length, pathStr.length) : pathStr,
target: apiServerAddress,
Expand Down
7 changes: 7 additions & 0 deletions frontend/server/consts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// The hack solution I found for solving:
// Responses fail randomly half way in a partial state, with the last sentence
// being: "Error occurred while trying to proxy request ..."
// Reference: https://github.com/chimurai/http-proxy-middleware/issues/171#issuecomment-439020716
export const HACK_FIX_HPM_PARTIAL_RESPONSE_HEADERS = {
Connection: 'keep-alive',
};
2 changes: 2 additions & 0 deletions frontend/server/handlers/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { createMinioClient, getObjectStream } from '../minio-helper';
import { Handler, Request, Response } from 'express';
import { Storage } from '@google-cloud/storage';
import proxy from 'http-proxy-middleware';
import { HACK_FIX_HPM_PARTIAL_RESPONSE_HEADERS } from '../consts';

/**
* ArtifactsQueryStrings describes the expected query strings key value pairs
Expand Down Expand Up @@ -299,6 +300,7 @@ export function getArtifactsProxyHandler({
return namespacedServiceGetter(namespace);
},
target: '/artifacts/get',
headers: HACK_FIX_HPM_PARTIAL_RESPONSE_HEADERS,
},
);
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/server/proxy-middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import express from 'express';
import proxy from 'http-proxy-middleware';
import { URL, URLSearchParams } from 'url';
import { HACK_FIX_HPM_PARTIAL_RESPONSE_HEADERS } from './consts';

export function _extractUrlFromReferer(proxyPrefix: string, referer = ''): string {
const index = referer.indexOf(proxyPrefix);
Expand Down Expand Up @@ -72,14 +73,13 @@ export default (app: express.Application, apisPrefix: string) => {
changeOrigin: true,
logLevel: process.env.NODE_ENV === 'test' ? 'warn' : 'debug',
target: 'http://127.0.0.1',

router: (req: any) => {
return _routePathWithReferer(proxyPrefix, req.path, req.headers.referer as string);
},

pathRewrite: (_: any, req: any) => {
return _rewritePath(proxyPrefix, req.path, req.query);
},
headers: HACK_FIX_HPM_PARTIAL_RESPONSE_HEADERS,
}),
);
};