Skip to content

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

None yet

Development

Successfully merging this pull request may close these issues.

2 participants