Skip to content

Commit

Permalink
Merge pull request #6 from Dynom/Cleanup
Browse files Browse the repository at this point in the history
Cleanup
  • Loading branch information
Dynom committed Apr 27, 2017
2 parents 5289a5b + 05fc1f0 commit 0b54482
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 28 deletions.
19 changes: 0 additions & 19 deletions handlers/favicon.go

This file was deleted.

2 changes: 1 addition & 1 deletion handlers/ratelimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func NewRateLimitHandler(l log.Logger, b *ratelimit.Bucket) func(h http.Handler)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
d := b.Take(1)
if d > 0 {
l.Log("msg", "Rate limiting", "delay", d)
l.Log("msg", "Rate limiting", "delay", d, "remote_addr", r.RemoteAddr)
time.Sleep(d)
}

Expand Down
7 changes: 3 additions & 4 deletions handlers/statuspaths.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ import (
)

func NewHTTPStatusPaths(_ log.Logger, paths []string, httpStatus int) func(h http.Handler) http.Handler {
var actions = make(map[string]bool, len(paths))
var pathMap = make(map[string]bool, len(paths))
for _, p := range paths {
if p == "" {
continue
}

actions[p] = true
pathMap[p] = true
}

return func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
action := r.URL.Path[1:]
if _, exists := actions[action]; action != "" && exists {
if _, exists := pathMap[r.URL.Path]; exists {
w.WriteHeader(httpStatus)
return
}
Expand Down
2 changes: 1 addition & 1 deletion handlers/urlparameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func NewValidateURLParameter(l log.Logger, allowedHosts []string) func(h http.Ha
return func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
queryURL := r.URL.Query().Get("url")
if !isValidQueryURL(queryURL, hosts) {
if queryURL != "" && !isValidQueryURL(queryURL, hosts) {
l.Log("error", "domain not registered", "QS", r.URL.RawQuery, "URL", queryURL)
http.Error(w, "Unregisterd domain", http.StatusNotAcceptable)
return
Expand Down
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,12 @@ func decorateHandler(l log.Logger, h http.Handler, b *ratelimit.Bucket) http.Han
decorators = append(
decorators,

// Checking on the route "health", doesn't support path-segment-stripping!
handlers.NewHTTPStatusPaths(l, []string{"health", "health/"}, http.StatusOK),
// Defining "health" end-points.
handlers.NewHTTPStatusPaths(l, []string{"/health", "/"}, http.StatusOK),

// Ignoring common foo requests
handlers.NewHTTPStatusPaths(l, []string{"/favicon"}, http.StatusNotFound),

handlers.NewIgnoreFaviconRequests(),
handlers.NewRequestLogger(l),
handlers.NewRateLimitHandler(l, b),
)
Expand Down

0 comments on commit 0b54482

Please sign in to comment.