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

Proposed enhancements #2

Closed
the42 opened this issue Apr 11, 2013 · 13 comments
Closed

Proposed enhancements #2

the42 opened this issue Apr 11, 2013 · 13 comments

Comments

@the42
Copy link

the42 commented Apr 11, 2013

CORSHandler
CacheHandler

and

GZipHandler come to mind. For the later there is an example here:
https://github.com/the42/schoolcalc/blob/master/webzapfen/webzapfen.go#L611

However, ideally, Handlers would be stackable.

@kisielk
Copy link
Contributor

kisielk commented Apr 11, 2013

Agree that all of them would be useful. I have a CORSHandler implemented in another (internal) project right now but I'm not sure I like the API yet. Currently looks like this:

type CORSHandler struct {
    // Handler is called to handle all requests.
    Handler http.Handler

    // AllowOrigin is an optional function that returns true if the origin is one for which CORS requests are allowed.
    // If AllowOrigin is nil, all origins are allowed.
    AllowOrigin func(origin string) bool

    // AllowMethod is an optional function that returns true if the method is one for which CORS requests are allowed.
    // If AllowMethod is false, all methods are allowed.
    AllowMethod func(method string) bool

    // AllowedHeaders is an optional function will be used to check the Access-Control-Request-Headers
    // header from any preflight requests. It returns true if the headers are allowed.
    // If AllowHeaders is nil, no headers are allowed.
    AllowHeaders func(headers []string) bool

    // ExposeHeaders is an optional list of headers that is
    ExposeHeaders []string

    // If SupportCredentials is true, the Access-Control-Allow-Credentials header is set to the string 'true'.
    SupportsCredentials bool

    // If MaxAge is not 0 the Access-Control-Max-Age header is set to this value.
    MaxAge int64
}
    CORSHandler adds the headers required for Cross-Origin Resource Sharing.
    If the requests do not meet the criteria at http://www.w3.org/TR/cors,
    no additioanl headers are set on the response but the wrapped Handler is
    still called.


func (h CORSHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

@kisielk
Copy link
Contributor

kisielk commented Jul 8, 2013

I also recently implemented gzip/flate, which doesn't have nearly as much tuning as the CORS handler. Would like some feedback on the CORS stuff though.

@philips
Copy link

philips commented Nov 21, 2013

@kisielk The CORS stuff looks pretty good to me.

@kisielk
Copy link
Contributor

kisielk commented Nov 21, 2013

@philips Cool :) Do you have any plans to use it? I could add it in some time on the weekend.

@philips
Copy link

philips commented Nov 21, 2013

@kisielk I just had to re-invent it, poorly, for etcd etcd-io/etcd#320

@kisielk
Copy link
Contributor

kisielk commented Nov 21, 2013

@philips Have a look at cors.go in https://gist.github.com/kisielk/0de4fc0375f56acf5f73

@philips
Copy link

philips commented Nov 22, 2013

@kisielk It makes sense to me based on implementing cors for etcd.

@philips
Copy link

philips commented Jan 20, 2014

@kisielk Would you mind if I cleaned up your gist and submitted a PR to gorilla/handlers?

@kisielk
Copy link
Contributor

kisielk commented Jan 20, 2014

Not at all

philips pushed a commit to philips/handlers that referenced this issue Feb 6, 2014
See the discussion here: gorilla#2
vincent-petithory pushed a commit to vincent-petithory/handlers that referenced this issue Oct 16, 2014
See the discussion here: gorilla#2
@awsmsrc
Copy link

awsmsrc commented Jul 5, 2015

would a basic auth handler be a good addition.

It would need to take a validate function that accepts a username, password and returns an error

I have one

@elithrar
Copy link
Contributor

elithrar commented Jul 5, 2015

@awsmsrc Might be worth opening a separate issue for that. If it's an existing repo that you'd like to merge in, provide the link. If it's fresh work, it helps to talk it over before committing too much time.

@kisielk
Copy link
Contributor

kisielk commented Aug 10, 2015

Going to close this for now. Separate issues can be filed for individual enhancements.

@kisielk kisielk closed this as completed Aug 10, 2015
njohns-grovo pushed a commit to njohns-grovo/handlers that referenced this issue Oct 26, 2015
See the discussion here: gorilla#2
@stokito
Copy link

stokito commented Jun 23, 2022

@awsmsrc Here I created a topic #231
Please join the discussion or share your version

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

6 participants