@@ -16,7 +16,7 @@ import (
1616// a JSON response body. An empty token will be returned if the middleware
1717// has not been applied (which will fail subsequent validation).
1818func Token (r * http.Request ) string {
19- if val , ok := context . GetOk (r , tokenKey ); ok {
19+ if val , err := contextGet (r , tokenKey ); err == nil {
2020 if maskedToken , ok := val .(string ); ok {
2121 return maskedToken
2222 }
@@ -29,7 +29,7 @@ func Token(r *http.Request) string {
2929// This is useful when you want to log the cause of the error or report it to
3030// client.
3131func FailureReason (r * http.Request ) error {
32- if val , ok := context . GetOk (r , errorKey ); ok {
32+ if val , err := contextGet (r , errorKey ); err == nil {
3333 if err , ok := val .(error ); ok {
3434 return err
3535 }
@@ -44,8 +44,8 @@ func FailureReason(r *http.Request) error {
4444// Note: You should not set this without otherwise securing the request from
4545// CSRF attacks. The primary use-case for this function is to turn off CSRF
4646// checks for non-browser clients using authorization tokens against your API.
47- func UnsafeSkipCheck (r * http.Request ) {
48- context . Set (r , skipCheckKey , true )
47+ func UnsafeSkipCheck (r * http.Request ) * http. Request {
48+ return contextSave (r , skipCheckKey , true )
4949}
5050
5151// TemplateField is a template helper for html/template that provides an <input> field
@@ -60,8 +60,7 @@ func UnsafeSkipCheck(r *http.Request) {
6060// <input type="hidden" name="gorilla.csrf.Token" value="<token>">
6161//
6262func TemplateField (r * http.Request ) template.HTML {
63- name , ok := context .GetOk (r , formKey )
64- if ok {
63+ if name , err := contextGet (r , formKey ); err == nil {
6564 fragment := fmt .Sprintf (`<input type="hidden" name="%s" value="%s">` ,
6665 name , Token (r ))
6766
0 commit comments