@ -11,7 +11,6 @@ import ( 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						"net/http"   
					 
					 
					 
						"net/http"   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						"os"   
					 
					 
					 
						"os"   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						"path"   
					 
					 
					 
						"path"   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						"path/filepath"   
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						"strings"   
					 
					 
					 
						"strings"   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						"code.gitea.io/gitea/modules/context"   
					 
					 
					 
						"code.gitea.io/gitea/modules/context"   
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -28,6 +27,7 @@ import ( 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					)  
					 
					 
					 
					)  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					func  storageHandler ( storageSetting  setting . Storage ,  prefix  string ,  objStore  storage . ObjectStorage )  func ( next  http . Handler )  http . Handler  {  
					 
					 
					 
					func  storageHandler ( storageSetting  setting . Storage ,  prefix  string ,  objStore  storage . ObjectStorage )  func ( next  http . Handler )  http . Handler  {  
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
						prefix  =  strings . Trim ( prefix ,  "/" )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						funcInfo  :=  routing . GetFuncInfo ( storageHandler ,  prefix )   
					 
					 
					 
						funcInfo  :=  routing . GetFuncInfo ( storageHandler ,  prefix )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
						return  func ( next  http . Handler )  http . Handler  {   
					 
					 
					 
						return  func ( next  http . Handler )  http . Handler  {   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							if  storageSetting . ServeDirect  {   
					 
					 
					 
							if  storageSetting . ServeDirect  {   
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -37,13 +37,15 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
										return   
					 
					 
					 
										return   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
									}   
					 
					 
					 
									}   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
									if  ! strings . HasPrefix ( req . URL . RequestURI ( ) ,  "/" + prefix )  {   
					 
					 
					 
									if  ! strings . HasPrefix ( req . URL . Path ,  "/" + prefix + "/" )  {   
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
										next . ServeHTTP ( w ,  req )   
					 
					 
					 
										next . ServeHTTP ( w ,  req )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
										return   
					 
					 
					 
										return   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
									}   
					 
					 
					 
									}   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
									routing . UpdateFuncInfo ( req . Context ( ) ,  funcInfo )   
					 
					 
					 
									routing . UpdateFuncInfo ( req . Context ( ) ,  funcInfo )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
									rPath  :=  strings . TrimPrefix ( req . URL . RequestURI ( ) ,  "/" + prefix )   
					 
					 
					 
									rPath  :=  strings . TrimPrefix ( req . URL . Path ,  "/" + prefix + "/" )   
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
									rPath  =  path . Clean ( "/"  +  strings . ReplaceAll ( rPath ,  "\\" ,  "/" ) ) [ 1 : ]   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
									u ,  err  :=  objStore . URL ( rPath ,  path . Base ( rPath ) )   
					 
					 
					 
									u ,  err  :=  objStore . URL ( rPath ,  path . Base ( rPath ) )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
									if  err  !=  nil  {   
					 
					 
					 
									if  err  !=  nil  {   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
										if  os . IsNotExist ( err )  ||  errors . Is ( err ,  os . ErrNotExist )  {   
					 
					 
					 
										if  os . IsNotExist ( err )  ||  errors . Is ( err ,  os . ErrNotExist )  {   
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -55,11 +57,12 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
										http . Error ( w ,  fmt . Sprintf ( "Error whilst getting URL for %s %s" ,  prefix ,  rPath ) ,  500 )   
					 
					 
					 
										http . Error ( w ,  fmt . Sprintf ( "Error whilst getting URL for %s %s" ,  prefix ,  rPath ) ,  500 )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
										return   
					 
					 
					 
										return   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
									}   
					 
					 
					 
									}   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
									http . Redirect (   
					 
					 
					 
									http . Redirect (   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
										w ,   
					 
					 
					 
										w ,   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
										req ,   
					 
					 
					 
										req ,   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
										u . String ( ) ,   
					 
					 
					 
										u . String ( ) ,   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
										301 ,   
					 
					 
					 
										http . StatusMovedPermanently ,   
				
			 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
									)   
					 
					 
					 
									)   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								} )   
					 
					 
					 
								} )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
							}   
					 
					 
					 
							}   
				
			 
			
		
	
	
		
		
			
				
					
						
						
						
							
								 
							 
						
					 
					 
					@ -70,22 +73,18 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
									return   
					 
					 
					 
									return   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								}   
					 
					 
					 
								}   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								prefix  :=  strings . Trim ( prefix ,  "/" )   
					 
					 
					 
								if  ! strings . HasPrefix ( req . URL . Path ,  "/" + prefix + "/" )  {   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								if  ! strings . HasPrefix ( req . URL . EscapedPath ( ) ,  "/" + prefix + "/" )  {   
					 
					 
					 
					 
				
			 
			
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
									next . ServeHTTP ( w ,  req )   
					 
					 
					 
									next . ServeHTTP ( w ,  req )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
									return   
					 
					 
					 
									return   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								}   
					 
					 
					 
								}   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								routing . UpdateFuncInfo ( req . Context ( ) ,  funcInfo )   
					 
					 
					 
								routing . UpdateFuncInfo ( req . Context ( ) ,  funcInfo )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								rPath  :=  strings . TrimPrefix ( req . URL . EscapedPath ( ) ,  "/" + prefix + "/" )   
					 
					 
					 
								rPath  :=  strings . TrimPrefix ( req . URL . Path ,  "/" + prefix + "/" )   
				
			 
			
				
				
			
		
	
		
		
			
				
					
					 
					 
					 
								rPath  =  strings . TrimPrefix ( rPath ,  "/" )   
					 
					 
					 
								rPath  =  path . Clean ( "/"  +  strings . ReplaceAll ( rPath ,  "\\" ,  " /" ) ) [ 1 : ]   
				
			 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					 
					 
					 
								if  rPath  ==  ""  {   
					 
					 
					 
								if  rPath  ==  ""  {   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
									http . Error ( w ,  "file not found" ,  404 )   
					 
					 
					 
									http . Error ( w ,  "file not found" ,  404 )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
									return   
					 
					 
					 
									return   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								}   
					 
					 
					 
								}   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								rPath  =  path . Clean ( "/"  +  filepath . ToSlash ( rPath ) )   
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								rPath  =  rPath [ 1 : ]   
					 
					 
					 
					 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
					
 
					 
					 
					 
					
 
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								fi ,  err  :=  objStore . Stat ( rPath )   
					 
					 
					 
								fi ,  err  :=  objStore . Stat ( rPath )   
				
			 
			
		
	
		
		
			
				
					
					 
					 
					 
								if  err  ==  nil  &&  httpcache . HandleTimeCache ( req ,  w ,  fi )  {   
					 
					 
					 
								if  err  ==  nil  &&  httpcache . HandleTimeCache ( req ,  w ,  fi )  {