Browse Source
			
			
			caddyhttp: Support single-line not matcher (#3228)
			
				* caddyhttp: Support single-line not matcher shortcut
* caddyhttp: Some tests, I guess
			
			
				master
			
			
		 
		
			
				
					
						 Francis Lavoie
					
					6 years ago
						Francis Lavoie
					
					6 years ago
					
						
							committed by
							
								 GitHub
								GitHub
							
						 
					
				 
				
			 
		 
		
			
				
					
					No known key found for this signature in database
					
						
							GPG Key ID: 4AEE18F83AFDEB23
						
					
				
			
		
		
		
	
		
			
				 2 changed files with 
24 additions and 
4 deletions
			 
			
		 
		
			
				- 
					
					
					 
					caddyconfig/httpcaddyfile/httptype_test.go
				
- 
					
					
					 
					modules/caddyhttp/matchers.go
				
				
				
					
						
							
								
									
	
		
		
			
				
					|  | @ -6,7 +6,7 @@ import ( | 
			
		
	
		
		
			
				
					|  |  | 	"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile" |  |  | 	"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile" | 
			
		
	
		
		
			
				
					|  |  | ) |  |  | ) | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  | func TestServerType(t *testing.T) { |  |  | func TestMatcherSyntax(t *testing.T) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | 	for i, tc := range []struct { |  |  | 	for i, tc := range []struct { | 
			
		
	
		
		
			
				
					|  |  | 		input       string |  |  | 		input       string | 
			
		
	
		
		
			
				
					|  |  | 		expectWarn  bool |  |  | 		expectWarn  bool | 
			
		
	
	
		
		
			
				
					|  | @ -15,7 +15,7 @@ func TestServerType(t *testing.T) { | 
			
		
	
		
		
			
				
					|  |  | 		{ |  |  | 		{ | 
			
		
	
		
		
			
				
					|  |  | 			input: `http://localhost
 |  |  | 			input: `http://localhost
 | 
			
		
	
		
		
			
				
					|  |  | 			@debug { |  |  | 			@debug { | 
			
		
	
		
		
			
				
					
					|  |  | 			  query showdebug=1 |  |  | 				query showdebug=1 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | 			} |  |  | 			} | 
			
		
	
		
		
			
				
					|  |  | 			`, |  |  | 			`, | 
			
		
	
		
		
			
				
					|  |  | 			expectWarn:  false, |  |  | 			expectWarn:  false, | 
			
		
	
	
		
		
			
				
					|  | @ -24,12 +24,32 @@ func TestServerType(t *testing.T) { | 
			
		
	
		
		
			
				
					|  |  | 		{ |  |  | 		{ | 
			
		
	
		
		
			
				
					|  |  | 			input: `http://localhost
 |  |  | 			input: `http://localhost
 | 
			
		
	
		
		
			
				
					|  |  | 			@debug { |  |  | 			@debug { | 
			
		
	
		
		
			
				
					
					|  |  | 			  query bad format |  |  | 				query bad format | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | 			} |  |  | 			} | 
			
		
	
		
		
			
				
					|  |  | 			`, |  |  | 			`, | 
			
		
	
		
		
			
				
					|  |  | 			expectWarn:  false, |  |  | 			expectWarn:  false, | 
			
		
	
		
		
			
				
					|  |  | 			expectError: true, |  |  | 			expectError: true, | 
			
		
	
		
		
			
				
					|  |  | 		}, |  |  | 		}, | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		{ | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			input: `http://localhost
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			@debug { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				not { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 					path /somepath* | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				} | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			} | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			`, | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			expectWarn:  false, | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			expectError: false, | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		}, | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		{ | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			input: `http://localhost
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			@debug { | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 				not path /somepath* | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			} | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			`, | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			expectWarn:  false, | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 			expectError: false, | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 		}, | 
			
		
	
		
		
			
				
					|  |  | 	} { |  |  | 	} { | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | 		adapter := caddyfile.Adapter{ |  |  | 		adapter := caddyfile.Adapter{ | 
			
		
	
	
		
		
			
				
					|  | 
 | 
			
		
	
								
							
						
					 
					
				 
			 
		
			
			
			
			
			
			
				
				
					
						
							
								
									
	
		
		
			
				
					|  | @ -559,7 +559,7 @@ func (m *MatchNot) UnmarshalCaddyfile(d *caddyfile.Dispenser) error { | 
			
		
	
		
		
			
				
					|  |  | 	for d.Next() { |  |  | 	for d.Next() { | 
			
		
	
		
		
			
				
					|  |  | 		var mp matcherPair |  |  | 		var mp matcherPair | 
			
		
	
		
		
			
				
					|  |  | 		matcherMap := make(map[string]RequestMatcher) |  |  | 		matcherMap := make(map[string]RequestMatcher) | 
			
		
	
		
		
			
				
					
					|  |  | 		for d.NextBlock(0) { |  |  | 		for d.NextArg() || d.NextBlock(0) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | 			matcherName := d.Val() |  |  | 			matcherName := d.Val() | 
			
		
	
		
		
			
				
					|  |  | 			mod, err := caddy.GetModule("http.matchers." + matcherName) |  |  | 			mod, err := caddy.GetModule("http.matchers." + matcherName) | 
			
		
	
		
		
			
				
					|  |  | 			if err != nil { |  |  | 			if err != nil { | 
			
		
	
	
		
		
			
				
					|  | 
 |