@@ -44,10 +44,18 @@ def handle_git(self):
4444 'GIT_HTTP_EXPORT_ALL' : '1' ,
4545 'PATH_INFO' : self .path .split ('?' )[0 ],
4646 'QUERY_STRING' : self .path .split ('?' )[1 ] if '?' in self .path else '' ,
47- 'CONTENT_TYPE' : self .headers .get ('Content-Type' , '' ),
4847 'REMOTE_ADDR' : self .client_address [0 ],
4948 }
5049
50+ for key , value in self .headers .items ():
51+ env_key = f"HTTP_{ key .upper ().replace ('-' , '_' )} "
52+ env [env_key ] = value
53+
54+ if 'Content-Type' in self .headers :
55+ env ['CONTENT_TYPE' ] = self .headers ['Content-Type' ]
56+ if 'Content-Length' in self .headers :
57+ env ['CONTENT_LENGTH' ] = self .headers ['Content-Length' ]
58+
5159 content_length = int (self .headers .get ('Content-Length' , 0 ))
5260 input_data = self .rfile .read (content_length ) if content_length > 0 else None
5361
@@ -61,33 +69,31 @@ def handle_git(self):
6169
6270 stdout_data , stderr_data = proc .communicate (input = input_data )
6371
64- if b'\r \n \r \n ' in stdout_data :
65- header_part , body = stdout_data .split (b'\r \n \r \n ' , 1 )
66- else :
67- header_part , body = stdout_data .split (b'\n \n ' , 1 )
72+ delimiter = b'\r \n \r \n ' if b'\r \n \r \n ' in stdout_data else b'\n \n '
73+ parts = stdout_data .split (delimiter , 1 )
74+
75+ header_part = parts [0 ]
76+ body = parts [1 ] if len (parts ) > 1 else b''
6877
69- headers = []
7078 status_code = 200
79+ response_headers = []
7180 for line in header_part .splitlines ():
7281 if b':' in line :
73- key , val = line .split (b':' , 1 )
74- key_str = key .decode ().strip ()
75- val_str = val .decode ().strip ()
76- if key_str .lower () == 'status' :
77- status_code = int (val_str .split (' ' )[0 ])
82+ k , v = line .split (b':' , 1 )
83+ k_str , v_str = k .decode ().strip (), v .decode ().strip ()
84+ if k_str .lower () == 'status' :
85+ status_code = int (v_str .split (' ' )[0 ])
7886 else :
79- headers .append ((key_str , val_str ))
87+ response_headers .append ((k_str , v_str ))
8088
8189 self .send_response (status_code )
82- for key , val in headers :
83- self .send_header (key , val )
90+ for k , v in response_headers :
91+ self .send_header (k , v )
8492 self .end_headers ()
85-
8693 self .wfile .write (body )
8794
8895 if stderr_data :
89- print (f"Git Error: { stderr_data .decode ('utf-8' , errors = 'replace' )} " , file = sys .stderr )
90-
96+ print (f"Backend Error: { stderr_data .decode ('utf-8' , errors = 'replace' )} " , file = sys .stderr )
9197
9298print (f"" )
9399print (f"--- Filesystem git HTTP bridge ---" )
0 commit comments