File tree Expand file tree Collapse file tree 2 files changed +11
-14
lines changed
src/proxy/processors/pre-processor Expand file tree Collapse file tree 2 files changed +11
-14
lines changed Original file line number Diff line number Diff line change @@ -9,24 +9,21 @@ const exec = async (req: {
99} ) => {
1010 const id = Date . now ( ) ;
1111 const timestamp = id ;
12- const pathBreakdown = processUrlPath ( req . originalUrl ) ;
1312 let type = 'default' ;
14- if ( pathBreakdown ) {
15- if ( pathBreakdown . gitPath . endsWith ( 'git-upload-pack' ) && req . method === 'GET' ) {
16- type = 'pull' ;
17- } else if (
18- pathBreakdown . gitPath . includes ( 'git-receive-pack' ) &&
19- req . method === 'POST' &&
20- req . headers [ 'content-type' ] === 'application/x-git-receive-pack-request'
21- ) {
22- type = 'push' ;
23- }
24- } // else failed to parse proxy URL path - which is logged in the parsing util
13+
14+ //inspect content-type headers to classify requests as push or pull operations
15+ // see git http protocol docs for more details: https://github.com/git/git/blob/master/Documentation/gitprotocol-http.adoc
16+ if ( req . headers [ 'content-type' ] === 'application/x-git-upload-pack-request' ) {
17+ type = 'pull' ;
18+ } else if ( req . headers [ 'content-type' ] === 'application/x-git-receive-pack-request' ) {
19+ type = 'push' ;
20+ }
2521
2622 // Proxy URLs take the form https://<git proxy domain>:<port>/<proxied domain>/<repoPath>
2723 // e.g. https://git-proxy-instance.com:8443/github.com/finos/git-proxy.git
2824 // We'll receive /github.com/finos/git-proxy.git as the req.url / req.originalUrl
2925 // Add protocol (assume SSL) to reconstruct full URL - noting path will start with a /
26+ const pathBreakdown = processUrlPath ( req . originalUrl ) ;
3027 let url = 'https:/' + ( pathBreakdown ?. repoPath ?? 'NOT-FOUND' ) ;
3128
3229 console . log ( `Parse action calculated repo URL: ${ url } for inbound URL path: ${ req . originalUrl } ` ) ;
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ describe('Pre-processor: parseAction', async () => {
2929 const req = {
3030 originalUrl : '/github.com/finos/git-proxy.git/git-upload-pack' ,
3131 method : 'GET' ,
32- headers : { } ,
32+ headers : { 'content-type' : 'application/x-git-upload-pack-request' } ,
3333 } ;
3434
3535 const action = await preprocessor . exec ( req ) ;
@@ -43,7 +43,7 @@ describe('Pre-processor: parseAction', async () => {
4343 const req = {
4444 originalUrl : '/finos/git-proxy.git/git-upload-pack' ,
4545 method : 'GET' ,
46- headers : { } ,
46+ headers : { 'content-type' : 'application/x-git-upload-pack-request' } ,
4747 } ;
4848
4949 const action = await preprocessor . exec ( req ) ;
You can’t perform that action at this time.
0 commit comments