forked from ory/fosite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresponse_handler.go
47 lines (39 loc) · 1.61 KB
/
response_handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package fosite
import "net/http"
// ResponseModeHandler provides a contract for handling custom response modes
type ResponseModeHandler interface {
// ResponseModes returns a set of supported response modes handled
// by the interface implementation.
//
// In an authorize request with any of the provide response modes
// methods `WriteAuthorizeResponse` and `WriteAuthorizeError` will be
// invoked to write the successful or error authorization responses respectively.
ResponseModes() ResponseModeTypes
// WriteAuthorizeResponse writes successful responses
//
// Following headers are expected to be set by default:
// header.Set("Cache-Control", "no-store")
// header.Set("Pragma", "no-cache")
WriteAuthorizeResponse(rw http.ResponseWriter, ar AuthorizeRequester, resp AuthorizeResponder)
// WriteAuthorizeError writes error responses
//
// Following headers are expected to be set by default:
// header.Set("Cache-Control", "no-store")
// header.Set("Pragma", "no-cache")
WriteAuthorizeError(rw http.ResponseWriter, ar AuthorizeRequester, err error)
}
type ResponseModeTypes []ResponseModeType
func (rs ResponseModeTypes) Has(item ResponseModeType) bool {
for _, r := range rs {
if r == item {
return true
}
}
return false
}
type DefaultResponseModeHandler struct{}
func (d *DefaultResponseModeHandler) ResponseModes() ResponseModeTypes { return nil }
func (d *DefaultResponseModeHandler) WriteAuthorizeResponse(rw http.ResponseWriter, ar AuthorizeRequester, resp AuthorizeResponder) {
}
func (d *DefaultResponseModeHandler) WriteAuthorizeError(rw http.ResponseWriter, ar AuthorizeRequester, err error) {
}