Actually set the response status correctly
Reading the docs helps.
This commit is contained in:
		
					parent
					
						
							
								6d70d29050
							
						
					
				
			
			
				commit
				
					
						26a9cf4911
					
				
			
		
					 1 changed files with 3 additions and 3 deletions
				
			
		
							
								
								
									
										6
									
								
								main.go
									
										
									
									
									
								
							
							
						
						
									
										6
									
								
								main.go
									
										
									
									
									
								
							| 
						 | 
					@ -41,8 +41,8 @@ func main() {
 | 
				
			||||||
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
 | 
						http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
		if r.Method != http.MethodGet {
 | 
							if r.Method != http.MethodGet {
 | 
				
			||||||
			log.Println("Wrong METHOD from", r.RemoteAddr)
 | 
								log.Println("Wrong METHOD from", r.RemoteAddr)
 | 
				
			||||||
			w.WriteHeader(http.StatusMethodNotAllowed)
 | 
					 | 
				
			||||||
			w.Header().Set("allow", http.MethodGet)
 | 
								w.Header().Set("allow", http.MethodGet)
 | 
				
			||||||
 | 
								w.WriteHeader(http.StatusMethodNotAllowed)
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -61,15 +61,15 @@ func main() {
 | 
				
			||||||
		username, password, ok := r.BasicAuth()
 | 
							username, password, ok := r.BasicAuth()
 | 
				
			||||||
		if !ok || username != validUsername || password != validPassword {
 | 
							if !ok || username != validUsername || password != validPassword {
 | 
				
			||||||
			log.Println("Unauthorized request from", r.RemoteAddr)
 | 
								log.Println("Unauthorized request from", r.RemoteAddr)
 | 
				
			||||||
			w.WriteHeader(http.StatusUnauthorized)
 | 
					 | 
				
			||||||
			w.Header().Set("www-authentication", "Basic realm=\"space-api\"")
 | 
								w.Header().Set("www-authentication", "Basic realm=\"space-api\"")
 | 
				
			||||||
 | 
								w.WriteHeader(http.StatusUnauthorized)
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if r.Method != http.MethodPut {
 | 
							if r.Method != http.MethodPut {
 | 
				
			||||||
			log.Println("Wrong METHOD from", r.RemoteAddr)
 | 
								log.Println("Wrong METHOD from", r.RemoteAddr)
 | 
				
			||||||
			w.WriteHeader(http.StatusMethodNotAllowed)
 | 
					 | 
				
			||||||
			w.Header().Set("allow", http.MethodPut)
 | 
								w.Header().Set("allow", http.MethodPut)
 | 
				
			||||||
 | 
								w.WriteHeader(http.StatusMethodNotAllowed)
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue