mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-11-04 03:27:23 -05:00 
			
		
		
		
	If scheme and port defy convention, it is an error
This prevents serving HTTPS over port 80 or HTTP over 443. It's confusing and we don't allow it.
This commit is contained in:
		
							parent
							
								
									202849055c
								
							
						
					
					
						commit
						ed0c0db6a3
					
				@ -338,7 +338,12 @@ func standardAddress(str string) (address, error) {
 | 
			
		||||
 | 
			
		||||
	// repeated or conflicting scheme is confusing, so error
 | 
			
		||||
	if scheme != "" && (port == "http" || port == "https") {
 | 
			
		||||
		return address{}, fmt.Errorf("[%s] scheme specified twice in address", str)
 | 
			
		||||
		return address{}, fmt.Errorf("[%s] scheme specified twice in address", input)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// error if scheme and port combination violate convention
 | 
			
		||||
	if (scheme == "http" && port == "443") || (scheme == "https" && port == "80") {
 | 
			
		||||
		return address{}, fmt.Errorf("[%s] scheme and port violate convention", input)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// standardize http and https ports to their respective port numbers
 | 
			
		||||
 | 
			
		||||
@ -27,6 +27,8 @@ func TestStandardAddress(t *testing.T) {
 | 
			
		||||
		{`:https`, "https", "", "443", false},
 | 
			
		||||
		{`http://localhost:https`, "", "", "", true}, // conflict
 | 
			
		||||
		{`http://localhost:http`, "", "", "", true},  // repeated scheme
 | 
			
		||||
		{`http://localhost:443`, "", "", "", true},   // not conventional
 | 
			
		||||
		{`https://localhost:80`, "", "", "", true},   // not conventional
 | 
			
		||||
		{`http://localhost`, "http", "localhost", "80", false},
 | 
			
		||||
		{`https://localhost`, "https", "localhost", "443", false},
 | 
			
		||||
		{`http://127.0.0.1`, "http", "127.0.0.1", "80", false},
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user