diff --git a/src/proxy/processors/pre-processor/parseAction.ts b/src/proxy/processors/pre-processor/parseAction.ts index 0707d9240..619deea93 100644 --- a/src/proxy/processors/pre-processor/parseAction.ts +++ b/src/proxy/processors/pre-processor/parseAction.ts @@ -9,24 +9,21 @@ const exec = async (req: { }) => { const id = Date.now(); const timestamp = id; - const pathBreakdown = processUrlPath(req.originalUrl); let type = 'default'; - if (pathBreakdown) { - if (pathBreakdown.gitPath.endsWith('git-upload-pack') && req.method === 'GET') { - type = 'pull'; - } else if ( - pathBreakdown.gitPath.includes('git-receive-pack') && - req.method === 'POST' && - req.headers['content-type'] === 'application/x-git-receive-pack-request' - ) { - type = 'push'; - } - } // else failed to parse proxy URL path - which is logged in the parsing util + + //inspect content-type headers to classify requests as push or pull operations + // see git http protocol docs for more details: https://github.com/git/git/blob/master/Documentation/gitprotocol-http.adoc + if (req.headers['content-type'] === 'application/x-git-upload-pack-request') { + type = 'pull'; + } else if (req.headers['content-type'] === 'application/x-git-receive-pack-request') { + type = 'push'; + } // Proxy URLs take the form https://:// // e.g. https://git-proxy-instance.com:8443/github.com/finos/git-proxy.git // We'll receive /github.com/finos/git-proxy.git as the req.url / req.originalUrl // Add protocol (assume SSL) to reconstruct full URL - noting path will start with a / + const pathBreakdown = processUrlPath(req.originalUrl); let url = 'https:/' + (pathBreakdown?.repoPath ?? 'NOT-FOUND'); console.log(`Parse action calculated repo URL: ${url} for inbound URL path: ${req.originalUrl}`); diff --git a/test/testParseAction.test.js b/test/testParseAction.test.js index 02686fc1d..3592cc081 100644 --- a/test/testParseAction.test.js +++ b/test/testParseAction.test.js @@ -29,7 +29,7 @@ describe('Pre-processor: parseAction', async () => { const req = { originalUrl: '/github.com/finos/git-proxy.git/git-upload-pack', method: 'GET', - headers: {}, + headers: { 'content-type': 'application/x-git-upload-pack-request' }, }; const action = await preprocessor.exec(req); @@ -43,7 +43,7 @@ describe('Pre-processor: parseAction', async () => { const req = { originalUrl: '/finos/git-proxy.git/git-upload-pack', method: 'GET', - headers: {}, + headers: { 'content-type': 'application/x-git-upload-pack-request' }, }; const action = await preprocessor.exec(req);