Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: gorilla/mux
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.6.2
Choose a base ref
...
head repository: gorilla/mux
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v1.7.0
Choose a head ref

Commits on May 17, 2018

  1. Copy the full SHA
    c856192 View commit details

Commits on May 26, 2018

  1. Initialize user map (#371)

    kalafut authored and kisielk committed May 26, 2018
    Copy the full SHA
    e0b5aba View commit details

Commits on Jun 5, 2018

  1. Update LICENSE & AUTHORS files. (#386)

    elithrar authored and kisielk committed Jun 5, 2018
    Copy the full SHA
    cb46983 View commit details

Commits on Aug 7, 2018

  1. Copy the full SHA
    815b8c6 View commit details
  2. Add test for multiple calls to Name().

    Fixes #394
    kisielk committed Aug 7, 2018
    Copy the full SHA
    e48e440 View commit details

Commits on Aug 30, 2018

  1. Add 1.11 to build in travis (#398)

    yershalom authored and elithrar committed Aug 30, 2018
    Copy the full SHA
    962c5be View commit details

Commits on Sep 2, 2018

  1. Drop support for Go < 1.7: remove gorilla/context (#391)

    * Drop support for Go < 1.7: remove gorilla/context
    * Remove Go < 1.7 from Travis CI config
    * Remove unneeded _native from context files
    fharding1 authored and elithrar committed Sep 2, 2018
    Copy the full SHA
    8771f97 View commit details
  2. Copy the full SHA
    cf6680b View commit details

Commits on Sep 3, 2018

  1. Always run on the latest stable Go version. (#402)

    Only run vet on the latest Go version.
    elithrar authored and kisielk committed Sep 3, 2018
    Copy the full SHA
    9e1f595 View commit details

Commits on Oct 12, 2018

  1. README.md: Update site URL

    kisielk authored Oct 12, 2018
    Copy the full SHA
    deb579d View commit details

Commits on Oct 24, 2018

  1. Copy the full SHA
    521ea7b View commit details

Commits on Oct 30, 2018

  1. Use subtests in mux_test.go (#415)

    kanozec authored and kisielk committed Oct 30, 2018
    Copy the full SHA
    3d80bc8 View commit details

Commits on Dec 7, 2018

  1. Improve subroute configuration propagation #422

    * Pull out common shared `routeConf` so that config is pushed on to child
    routers and routes.
    * Removes obsolete usages of `parentRoute`
    * Add tests defining compositional behavior
    * Exercise `copyRouteConf` for posterity
    jwilner authored and elithrar committed Dec 7, 2018
    Copy the full SHA
    758eb64 View commit details
  2. Add stalebot config (#424)

    elithrar authored and kisielk committed Dec 7, 2018
    Copy the full SHA
    419fd9f View commit details

Commits on Dec 8, 2018

  1. Copy the full SHA
    d2b5d13 View commit details

Commits on Dec 17, 2018

  1. remove redundant code that remove support gorilla/context (#427)

    * remove redundant code that remove support gorilla/context
    
    * backward compatible for remove redundant code
    alimy authored and elithrar committed Dec 17, 2018
    2
    Copy the full SHA
    6137e19 View commit details

Commits on Dec 25, 2018

  1. Replace domain.com with example.com (#434)

    Because domain.com is an actual business, example.com should be used for example purposes.
    RaeesBhatti authored and kisielk committed Dec 25, 2018
    Copy the full SHA
    a31c178 View commit details

Commits on Dec 28, 2018

  1. [bugfix] Clear matchErr when traversing subrouters.

    Previously, when searching for a match, matchErr would be erroneously set, and prevent middleware from running (no match == no middleware runs).
    
    This fix clears matchErr before traversing the next subrouter in a multi-subrouter router.
    tomare authored and elithrar committed Dec 28, 2018
    Copy the full SHA
    ef912dd View commit details

Commits on Jan 4, 2019

  1. getHost() now returns full host & port information (#383)

    Previously, getHost only returned the host. As it now returns the
    port as well, any .Host matches on a route will need to be updated
    to also support matching on the port for cases where the port is
    non default, eg: 80 for http or 443 for https.
    santsai authored and elithrar committed Jan 4, 2019
    2
    Copy the full SHA
    f3ff42f View commit details

Commits on Jan 8, 2019

  1. Ignore ErrNotFound while matching Subrouters (#438)

    MatchErr is set by the router to ErrNotFound if no route matches. If
    no route of a Subrouter matches the error can by safely ignored. This
    implementation only ignores these errors and does not ignore other
    errors like ErrMethodMismatch.
    g-w authored and elithrar committed Jan 8, 2019
    Copy the full SHA
    08e7f80 View commit details

Commits on Jan 25, 2019

  1. Call WriteHeader after setting other header(s) in the example (#442)

    From the docs: Changing the header map after a call to WriteHeader (or
    Write) has no effect unless the modified headers are
    trailers.
    timucingelici authored and elithrar committed Jan 25, 2019
    Copy the full SHA
    797e653 View commit details
  2. Copy the full SHA
    a796238 View commit details
Showing with 774 additions and 321 deletions.
  1. +8 −0 .github/release-drafter.yml
  2. +12 −0 .github/stale.yml
  3. +4 −3 .travis.yml
  4. +8 −0 AUTHORS
  5. +1 −1 LICENSE
  6. +8 −8 README.md
  7. +0 −6 context_native.go → context.go
  8. +0 −26 context_gorilla.go
  9. +0 −40 context_gorilla_test.go
  10. +0 −2 context_native_test.go → context_test.go
  11. +1 −1 example_authentication_middleware_test.go
  12. +1 −0 go.mod
  13. +63 −3 middleware_test.go
  14. +68 −55 mux.go
  15. +552 −71 mux_test.go
  16. +5 −9 regexp.go
  17. +43 −96 route.go
8 changes: 8 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Config for https://github.com/apps/release-drafter
template: |
<summary of changes here>
## CHANGELOG
$CHANGES
12 changes: 12 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
daysUntilStale: 60
daysUntilClose: 7
# Issues with these labels will never be considered stale
exemptLabels:
- v2
- needs-review
- work-required
staleLabel: stale
markComment: >
This issue has been automatically marked as stale because it hasn't seen
a recent update. It'll be automatically closed in a few days.
closeComment: false
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -3,12 +3,13 @@ sudo: false

matrix:
include:
- go: 1.5.x
- go: 1.6.x
- go: 1.7.x
- go: 1.8.x
- go: 1.9.x
- go: 1.10.x
- go: 1.11.x
- go: 1.x
env: LATEST=true
- go: tip
allow_failures:
- go: tip
@@ -19,5 +20,5 @@ install:
script:
- go get -t -v ./...
- diff -u <(echo -n) <(gofmt -d .)
- go tool vet .
- if [[ "$LATEST" = true ]]; then go tool vet .; fi
- go test -v -race ./...
8 changes: 8 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This is the official list of gorilla/mux authors for copyright purposes.
#
# Please keep the list sorted.

Google LLC (https://opensource.google.com/)
Kamil Kisielk <kamil@kamilkisiel.net>
Matt Silverlock <matt@eatsleeprepeat.net>
Rodrigo Moraes (https://github.com/moraes)
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2012 Rodrigo Moraes. All rights reserved.
Copyright (c) 2012-2018 The Gorilla Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

![Gorilla Logo](http://www.gorillatoolkit.org/static/images/gorilla-icon-64.png)

http://www.gorillatoolkit.org/pkg/mux
https://www.gorillatoolkit.org/pkg/mux

Package `gorilla/mux` implements a request router and dispatcher for matching incoming requests to
their respective handler.
@@ -88,7 +88,7 @@ r := mux.NewRouter()
// Only matches if domain is "www.example.com".
r.Host("www.example.com")
// Matches a dynamic subdomain.
r.Host("{subdomain:[a-z]+}.domain.com")
r.Host("{subdomain:[a-z]+}.example.com")
```

There are several other matchers that can be added. To match path prefixes:
@@ -238,13 +238,13 @@ This also works for host and query value variables:

```go
r := mux.NewRouter()
r.Host("{subdomain}.domain.com").
r.Host("{subdomain}.example.com").
Path("/articles/{category}/{id:[0-9]+}").
Queries("filter", "{filter}").
HandlerFunc(ArticleHandler).
Name("article")

// url.String() will be "http://news.domain.com/articles/technology/42?filter=gorilla"
// url.String() will be "http://news.example.com/articles/technology/42?filter=gorilla"
url, err := r.Get("article").URL("subdomain", "news",
"category", "technology",
"id", "42",
@@ -264,7 +264,7 @@ r.HeadersRegexp("Content-Type", "application/(text|json)")
There's also a way to build only the URL host or path for a route: use the methods `URLHost()` or `URLPath()` instead. For the previous route, we would do:

```go
// "http://news.domain.com/"
// "http://news.example.com/"
host, err := r.Get("article").URLHost("subdomain", "news")

// "/articles/technology/42"
@@ -275,12 +275,12 @@ And if you use subrouters, host and path defined separately can be built as well

```go
r := mux.NewRouter()
s := r.Host("{subdomain}.domain.com").Subrouter()
s := r.Host("{subdomain}.example.com").Subrouter()
s.Path("/articles/{category}/{id:[0-9]+}").
HandlerFunc(ArticleHandler).
Name("article")

// "http://news.domain.com/articles/technology/42"
// "http://news.example.com/articles/technology/42"
url, err := r.Get("article").URL("subdomain", "news",
"category", "technology",
"id", "42")
@@ -503,8 +503,8 @@ package main

func HealthCheckHandler(w http.ResponseWriter, r *http.Request) {
// A very simple health check.
w.WriteHeader(http.StatusOK)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)

// In the future we could report back on the status of our DB, or our cache
// (e.g. Redis) by performing a simple PING, and include them in the response.
6 changes: 0 additions & 6 deletions context_native.go → context.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build go1.7

package mux

import (
@@ -18,7 +16,3 @@ func contextSet(r *http.Request, key, val interface{}) *http.Request {

return r.WithContext(context.WithValue(r.Context(), key, val))
}

func contextClear(r *http.Request) {
return
}
26 changes: 0 additions & 26 deletions context_gorilla.go

This file was deleted.

40 changes: 0 additions & 40 deletions context_gorilla_test.go

This file was deleted.

2 changes: 0 additions & 2 deletions context_native_test.go → context_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// +build go1.7

package mux

import (
2 changes: 1 addition & 1 deletion example_authentication_middleware_test.go
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ func Example_authenticationMiddleware() {
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// Do something here
})
amw := authenticationMiddleware{}
amw := authenticationMiddleware{make(map[string]string)}
amw.Populate()
r.Use(amw.Middleware)
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module github.com/gorilla/mux
66 changes: 63 additions & 3 deletions middleware_test.go
Original file line number Diff line number Diff line change
@@ -151,7 +151,7 @@ func TestMiddlewareExecution(t *testing.T) {
// Test handler-only call
router.ServeHTTP(rw, req)

if bytes.Compare(rw.Body.Bytes(), handlerStr) != 0 {
if !bytes.Equal(rw.Body.Bytes(), handlerStr) {
t.Fatal("Handler response is not what it should be")
}

@@ -166,7 +166,7 @@ func TestMiddlewareExecution(t *testing.T) {
})

router.ServeHTTP(rw, req)
if bytes.Compare(rw.Body.Bytes(), append(mwStr, handlerStr...)) != 0 {
if !bytes.Equal(rw.Body.Bytes(), append(mwStr, handlerStr...)) {
t.Fatal("Middleware + handler response is not what it should be")
}
}
@@ -368,10 +368,70 @@ func TestCORSMethodMiddleware(t *testing.T) {
t.Errorf("Expected body '%s', found '%s'", tt.response, rr.Body.String())
}

allowedMethods := rr.HeaderMap.Get("Access-Control-Allow-Methods")
allowedMethods := rr.Header().Get("Access-Control-Allow-Methods")

if allowedMethods != tt.expectedAllowedMethods {
t.Errorf("Expected Access-Control-Allow-Methods '%s', found '%s'", tt.expectedAllowedMethods, allowedMethods)
}
}
}

func TestMiddlewareOnMultiSubrouter(t *testing.T) {
first := "first"
second := "second"
notFound := "404 not found"

router := NewRouter()
firstSubRouter := router.PathPrefix("/").Subrouter()
secondSubRouter := router.PathPrefix("/").Subrouter()

router.NotFoundHandler = http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
rw.Write([]byte(notFound))
})

firstSubRouter.HandleFunc("/first", func(w http.ResponseWriter, r *http.Request) {

})

secondSubRouter.HandleFunc("/second", func(w http.ResponseWriter, r *http.Request) {

})

firstSubRouter.Use(func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(first))
h.ServeHTTP(w, r)
})
})

secondSubRouter.Use(func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(second))
h.ServeHTTP(w, r)
})
})

rw := NewRecorder()
req := newRequest("GET", "/first")

router.ServeHTTP(rw, req)
if rw.Body.String() != first {
t.Fatalf("Middleware did not run: expected %s middleware to write a response (got %s)", first, rw.Body.String())
}

rw = NewRecorder()
req = newRequest("GET", "/second")

router.ServeHTTP(rw, req)
if rw.Body.String() != second {
t.Fatalf("Middleware did not run: expected %s middleware to write a response (got %s)", second, rw.Body.String())
}

rw = NewRecorder()
req = newRequest("GET", "/second/not-exist")

router.ServeHTTP(rw, req)
if rw.Body.String() != notFound {
t.Fatalf("Notfound handler did not run: expected %s for not-exist, (got %s)", notFound, rw.Body.String())
}
}
Loading