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

Use headers for routing #157

Closed
jhspaybar opened this issue May 13, 2016 · 2 comments
Closed

Use headers for routing #157

jhspaybar opened this issue May 13, 2016 · 2 comments

Comments

@jhspaybar
Copy link

Some RPC systems like those used by AWS expect a header to determine the method being invoked. It doesn't look like this is actually part of the google protobuf option used to generate the proxy, but I had envisioned something like headers: [["foo", "bar"], ["other", "val"]] which would allow me to trigger routing if the header foo=bar and other=val. Is this the right place to discuss something like this, or should I make an issue in the googleapis repo?

@yugui
Copy link
Member

yugui commented May 16, 2016

I never add the feature unless it is "standardized" in googleapis repo or I realize that the use case is common enough.
For now, I'm not sure if the use case is really common.

In my understanding, such custom dispatch tends to be implemented as a custom VERB.
https://github.com/googleapis/googleapis/blob/master/google/api/http.proto#L210

Also if we really need this kind of "pattern matching", we would also need to discuss what kind of inputs should be involved into the pattern match. Why is it applied to only headers? Why not match with query parameters?

For uncommon use cases, you can combine any custom Go http handler with top of the one grpc-gateway generates.
e.g.

func TagVerbFilter(h http.Handler) http.Handler {
  return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request){
    if r.Header.Get("foo") == "bar" && r.Header.Get("other") == "val" {
      r2 := new(http.Request)
      *r2 = *r
      u, err := url.Parse(r.URL.String() + ":myVerb"
      if err != nil {
        http.Error(w, err.Error(), http.StatusInternalServerError)
        return
      }
      r2.URL = u
      r = r2
    }
    h.ServeHTTP(w, r)
  })
}

@achew22
Copy link
Collaborator

achew22 commented Jan 4, 2017

Just doing a little bit of tidying. I hope that your question was answered in a way that let your project continue. If you have any more questions feel free to open another issue.

@achew22 achew22 closed this as completed Jan 4, 2017
@tamalsaha tamalsaha mentioned this issue Mar 30, 2017
1 task
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

No branches or pull requests

3 participants