예제 #1
0
파일: server.go 프로젝트: 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
		}
	})
}
예제 #2
0
파일: server.go 프로젝트: 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
		}
	})
}
예제 #3
0
파일: server.go 프로젝트: junghao/haz
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
		}
	})
}
예제 #4
0
파일: server.go 프로젝트: 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
		}
	})
}
예제 #5
0
파일: server.go 프로젝트: 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
		}
	})
}