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

Disable caching on all tequilapi responses #217

Merged
merged 3 commits into from Apr 9, 2018

Conversation

Projects
None yet
4 participants
@tadovas
Copy link
Member

commented Apr 9, 2018

No description provided.


type cacheControl struct {
originalHandler http.Handler
}

This comment has been minimized.

Copy link
@donce

donce Apr 9, 2018

Contributor

This is duplicated with corsHandler - only ServeHTTP differs.

We can DRY this by having something like this:

type handlerWrapper struct {
  originalHandler http.Handler
  serveHttp func(resp http.ResponseWriter, req *http.Request)
}

func DisableCaching(original http.Handler) http.Handler {
  return &handlerWrapper{original, serveDisabledCaching}
}

func serveDisabledCaching...

and same applies for ApplyCors.

This comment has been minimized.

Copy link
@tadovas

tadovas Apr 9, 2018

Author Member

Possible. But only two structures at the moment. Maybe when count reaches 3 :)

This comment has been minimized.

Copy link
@Waldz

Waldz Apr 9, 2018

Member

It's too little problem to DRY, better to have decoupled qualities

@donce

donce approved these changes Apr 9, 2018

func (server *apiServer) Stop() {
if server.listener == nil {
return
}
server.listener.Close()
}

// Wait method waits for http server to finish handling requets (i.e. when Stop() was called)

This comment has been minimized.

Copy link
@zolia

zolia Apr 9, 2018

Member

'requets' -> 'requests' typo

func NewServer(address string, port int, handler http.Handler) APIServer {
server := apiServer{
make(chan error, 1),
ApplyCors(handler),
DisableCaching(ApplyCors(handler)),

This comment has been minimized.

Copy link
@zolia

zolia Apr 9, 2018

Member

It would be nicer to see headers being applied sequentially, it would be good to keep an order of functions being applied to be reversed.

This comment has been minimized.

Copy link
@tadovas

tadovas Apr 9, 2018

Author Member

Nice idea. It could be improvement with composer which takes request, a list of decorators and applies them in given order like this:
Decorate(originRequest , ApplyCors, DisableCaching ... etc... )

@Waldz

Waldz approved these changes Apr 9, 2018

@tadovas tadovas merged commit 4a7abaf into master Apr 9, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@tadovas tadovas deleted the improvement/disable-caching-on-tequilapi branch Apr 9, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.