Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for percent-encoded slashes in parameter values #140

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

coditect
Copy link

Passing percent-encoded slashes in URL parameter values is a real, albeit uncommon, use case. This pull request leverages new features introduced in Go 1.5 to enable httprouter to differentiate between the literal slashes that delimit path segments in a URL from encoded slashes that should be treated as data.

Given a simple HTTP server like this:

package main

import (
    "fmt"
    "github.com/julienschmidt/httprouter"
    "net/http"
)

func main() {
    server := httprouter.New()
    server.GET("/version/:v", handle)
    http.ListenAndServe(":8080", server)
}

func handle(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
    fmt.Fprintf(w, "Version is %s\n", p.ByName("v")
}

A GET request to /version/go%2f1.6 should produce a response like this:

HTTP/1.1 200 OK
Content-Length: 17
Content-Type: text/plain; charset=utf-8

Version is go/1.6

@julienschmidt julienschmidt self-assigned this Jan 13, 2020
similark pushed a commit to similarweb/httprouter that referenced this pull request May 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
v2
Routing
Development

Successfully merging this pull request may close these issues.

None yet

2 participants