Esempio n. 1
0
File: server.go Progetto: GeoNet/haz
func inbound(h http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		switch r.Method {
		case "GET":
			h.ServeHTTP(w, r)
		default:
			weft.Write(w, r, &weft.MethodNotAllowed)
			weft.MethodNotAllowed.Count()
			return
		}
	})
}
Esempio n. 2
0
File: server.go Progetto: GeoNet/haz
func inbound(h http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		switch r.Method {
		case "GET":
			// Default browser cache control (for CORS requests)
			w.Header().Set("Cache-Control", maxAge10)
			// Enable CORS
			w.Header().Set("Access-Control-Allow-Methods", "GET")
			w.Header().Set("Access-Control-Allow-Origin", "*")

			h.ServeHTTP(w, r)
		default:
			weft.Write(w, r, &weft.MethodNotAllowed)
			weft.MethodNotAllowed.Count()
			return
		}
	})
}
Esempio n. 3
0
func inbound(h http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		// TODO this is a browser cache directive and does not make a lot
		// of sense for an API.
		w.Header().Set("Cache-Control", maxAge10)
		switch r.Method {
		case "GET":
			// Routing is based on Accept query parameters
			// e.g., version=1 in application/json;version=1
			// so caching must Vary based on Accept.
			w.Header().Set("Vary", "Accept")

			h.ServeHTTP(w, r)
		default:
			weft.Write(w, r, &weft.MethodNotAllowed)
			weft.MethodNotAllowed.Count()
			return
		}
	})
}
Esempio n. 4
0
File: server.go Progetto: GeoNet/mtr
// inbound wraps the mux and adds basic auth.
func inbound(h http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		switch r.Method {
		case "PUT", "DELETE", "POST":
			if user, password, ok := r.BasicAuth(); ok && userW == user && keyW == password {
				h.ServeHTTP(w, r)
			} else {
				http.Error(w, "Access denied", http.StatusUnauthorized)
				mtrapp.StatusUnauthorized.Inc()
				return
			}
		case "GET":
			h.ServeHTTP(w, r)
		default:
			weft.Write(w, r, &weft.MethodNotAllowed)
			weft.MethodNotAllowed.Count()
			return
		}
	})
}
Esempio n. 5
0
File: server.go Progetto: GeoNet/haz
func inbound(h http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		switch r.Method {
		case "GET":
			// Routing is based on Accept query parameters
			// e.g., version=1 in application/json;version=1
			// so caching must Vary based on Accept.
			w.Header().Set("Vary", "Accept")

			// Default browser cache control (for CORS requests)
			w.Header().Set("Cache-Control", maxAge10)
			// Enable CORS
			w.Header().Set("Access-Control-Allow-Methods", "GET")
			w.Header().Set("Access-Control-Allow-Origin", "*")

			h.ServeHTTP(w, r)
		default:
			weft.Write(w, r, &weft.MethodNotAllowed)
			weft.MethodNotAllowed.Count()
			return
		}
	})
}