Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions src/proxy/processors/pre-processor/parseAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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://<git proxy domain>:<port>/<proxied domain>/<repoPath>
// 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}`);
Expand Down
4 changes: 2 additions & 2 deletions test/testParseAction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Loading