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)
| 147 | // it first looks at the 'Cookie' and then the 'Authorization' header. If no credential is found, |
| 148 | // it returns an empty string. |
| 149 | func GetCredential(r *http.Request) (string, error) { |
| 150 | ret, err := getSessionKeyFromCookie(r) |
| 151 | if err != nil { |
| 152 | return "", errors.Wrap(err, "getting session key from cookie") |
| 153 | } |
| 154 | if ret != "" { |
| 155 | return ret, nil |
| 156 | } |
| 157 | |
| 158 | ret, err = getSessionKeyFromAuth(r) |
| 159 | if err != nil { |
| 160 | return "", errors.Wrap(err, "getting session key from Authorization header") |
| 161 | } |
| 162 | |
| 163 | return ret, nil |
| 164 | } |