mirror of
				https://github.com/coredns/coredns.git
				synced 2025-10-31 02:03:20 -04:00 
			
		
		
		
	middleware/httpproxy: add debug queries (#446)
* middleware/httproxy: implement debug queries Not too useful at the moment, but o-o.debug queries are supported and return the Comment from dns.google.com. Note that this is not always set. * improve documentation * Testing cleanups
This commit is contained in:
		
							
								
								
									
										20
									
								
								middleware/pkg/debug/debug.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								middleware/pkg/debug/debug.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,20 @@ | ||||
| package debug | ||||
|  | ||||
| import "strings" | ||||
|  | ||||
| const Name = "o-o.debug." | ||||
|  | ||||
| // IsDebug checks if name is a debugging name, i.e. starts with o-o.debug. | ||||
| // it returns the empty string if it is not a debug message, otherwise it will return the | ||||
| // name with o-o.debug. stripped off. Must be called with name lowercased. | ||||
| func IsDebug(name string) string { | ||||
| 	if len(name) == len(Name) { | ||||
| 		return "" | ||||
| 	} | ||||
| 	name = strings.ToLower(name) | ||||
| 	debug := strings.HasPrefix(name, Name) | ||||
| 	if !debug { | ||||
| 		return "" | ||||
| 	} | ||||
| 	return name[len(Name):] | ||||
| } | ||||
							
								
								
									
										21
									
								
								middleware/pkg/debug/debug_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								middleware/pkg/debug/debug_test.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,21 @@ | ||||
| package debug | ||||
|  | ||||
| import ( | ||||
| 	"strings" | ||||
| 	"testing" | ||||
| ) | ||||
|  | ||||
| func TestIsDebug(t *testing.T) { | ||||
| 	if ok := IsDebug("o-o.debug.miek.nl."); ok != "miek.nl." { | ||||
| 		t.Errorf("expected o-o.debug.miek.nl. to be debug") | ||||
| 	} | ||||
| 	if ok := IsDebug(strings.ToLower("o-o.Debug.miek.nl.")); ok != "miek.nl." { | ||||
| 		t.Errorf("expected o-o.Debug.miek.nl. to be debug") | ||||
| 	} | ||||
| 	if ok := IsDebug("i-o.debug.miek.nl."); ok != "" { | ||||
| 		t.Errorf("expected i-o.Debug.miek.nl. to be non-debug") | ||||
| 	} | ||||
| 	if ok := IsDebug(strings.ToLower("i-o.Debug.")); ok != "" { | ||||
| 		t.Errorf("expected o-o.Debug. to be non-debug") | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user