dimfeld / httptreemux

High-speed, flexible tree-based HTTP router for Go.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

OAuth package goth does not work

dc0d opened this issue · comments

Apparently query parameters which should be available via req.URL.Query().Get("some-key") get removed by httptreemux. Not that this is necessarily a bug, but if this is by design, one should be aware of that.

Can you provide some code sample? My package doesn't modify req.URL so offhand I'm not sure why you would be seeing this problem.

Thansk for the reply! I've just replaced package github.com/gorilla/pat with httptreemux in goth's own example; https://github.com/markbates/goth/blob/master/examples/main.go.

Ok, thanks. I may not be able to look into this for a week or so, but I definitely will figure out what's going on there.

My idiocy! I can't check it right now; but I remembered the query parameter was not actually got a value in my code. I'll check & report back.

Using this method from pat:

func registerVars(r *http.Request, vars map[string]string) {
    parts, i := make([]string, len(vars)), 0
    for key, value := range vars {
        parts[i] = url.QueryEscape(":"+key) + "=" + url.QueryEscape(value)
        i++
    }
    q := strings.Join(parts, "&")
    if r.URL.RawQuery == "" {
        r.URL.RawQuery = q
    } else {
        r.URL.RawQuery += "&" + q
    }
}

I've added missing parameters. It's that pat adds parameters as query params to req.URL.RawQuery automatically (& apparently some packages like goth use query parameters). pat does this to make a query-included url look like a REST one.

Excuse me for any inconveniences.

Oh that's interesting. I'll add a section to the README pointing out this difference. Thanks for following up on this!