GetCredential extracts a session key from the request from the request header. Concretely, it first looks at the 'Cookie' and then the 'Authorization' header. If no credential is found, it returns an empty string.
(r *http.Request)
| 85 | // it first looks at the 'Cookie' and then the 'Authorization' header. If no credential is found, |
| 86 | // it returns an empty string. |
| 87 | func GetCredential(r *http.Request) (string, error) { |
| 88 | ret, err := getSessionKeyFromCookie(r) |
| 89 | if err != nil { |
| 90 | return "", errors.Wrap(err, "getting session key from cookie") |
| 91 | } |
| 92 | if ret != "" { |
| 93 | return ret, nil |
| 94 | } |
| 95 | |
| 96 | ret, err = getSessionKeyFromAuth(r) |
| 97 | if err != nil { |
| 98 | return "", errors.Wrap(err, "getting session key from Authorization header") |
| 99 | } |
| 100 | |
| 101 | return ret, nil |
| 102 | } |
| 103 | |
| 104 | // getSessionKeyFromCookie reads and returns a session key from the cookie sent by the |
| 105 | // request. If no session key is found, it returns an empty string |
no test coverage detected