Ejemplo n.º 1
0
func rootHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.WriteText("%s<br />", w.GetVar("foo"))

	// run with TRAFFIC_ENV=production to get the "bar" value
	// from the production section of the config file
	w.WriteText("%s<br />", w.GetVar("bar"))
}
Ejemplo n.º 2
0
func CheckForDdosString(w traffic.ResponseWriter, r *traffic.Request) {
	for k, _ := range uriFragments {
		fmt.Printf("Searching for %s in %s", k, r.RequestURI)
		if strings.Contains(r.RequestURI, k) {
			fmt.Printf("Found %s", k)
			w.WriteHeader(http.StatusGatewayTimeout)
			w.WriteText("connection timed out")
		}
	}
}
Ejemplo n.º 3
0
func rootHandler(w traffic.ResponseWriter, r *traffic.Request) {
	logger := w.GetVar("chromelogger").(*chromelogger.Logger)

	logger.Log("Hello")
	logger.Log(map[string]string{
		"foo": "bar",
	})

	w.WriteText("Hello, check your Chrome console after activating the Chrome Logger extension.\n")
}
Ejemplo n.º 4
0
// If the request path is "/ping", it writes PONG in the response and returns without calling the next middleware
// Otherwise it sets the variable "PING" with PONG as value and calls the next  middleware.
// The next middleware and the final handler can get that variable with:
//   w.GetVar("ping")
func (c *PingMiddleware) ServeHTTP(w traffic.ResponseWriter, r *traffic.Request, next traffic.NextMiddlewareFunc) {
	if r.URL.Path == "/ping" {
		w.WriteText("pong\n")

		return
	}

	if nextMiddleware := next(); nextMiddleware != nil {
		w.SetVar("ping", "pong")
		nextMiddleware.ServeHTTP(w, r, next)
	}

	return
}
Ejemplo n.º 5
0
func rootHandler(w traffic.ResponseWriter, r *traffic.Request) {
	traffic.Logger().Print("Hello")
	w.WriteText("Hello World\n")
}
Ejemplo n.º 6
0
func pageHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.WriteText("Category ID: %s\n", r.Param("category_id"))
	w.WriteText("Page ID: %s\n", r.Param("id"))
}
Ejemplo n.º 7
0
func root(w traffic.ResponseWriter, r *traffic.Request) {
	w.WriteText("Router var foo: %v.\n", w.GetVar("foo"))
	w.WriteText("Middleware var ping: %v\n", w.GetVar("ping"))
}
Ejemplo n.º 8
0
func rootHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.WriteText("Hello World\n")
}
Ejemplo n.º 9
0
func customNotFoundHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.WriteHeader(http.StatusNotFound)
	w.WriteText("Page not found: %s\n", r.URL.Path)
}
Ejemplo n.º 10
0
func errorHandler(w traffic.ResponseWriter, r *traffic.Request, err interface{}) {
	w.WriteText("This is a custom error page <br />\n")
	w.WriteText("Recovered from `%v`", err)
}
Ejemplo n.º 11
0
func checkPrivatePageApiKey(w traffic.ResponseWriter, r *traffic.Request) {
	if r.Param("private_api_key") != "bar" {
		w.WriteHeader(http.StatusUnauthorized)
		w.WriteText("Not authorized\n")
	}
}
Ejemplo n.º 12
0
func checkApiKey(w traffic.ResponseWriter, r *traffic.Request) {
	if r.Param("api_key") != "foo" {
		w.WriteHeader(http.StatusUnauthorized)
		w.WriteText("Not authorized\n")
	}
}
Ejemplo n.º 13
0
func privatePageHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.WriteText("Hello Private Page\n")
}
Ejemplo n.º 14
0
func serverSideHandler(w traffic.ResponseWriter, r *traffic.Request) {
	w.WriteText("Resource not available\n")
}