5
5
"errors"
6
6
"net/http"
7
7
"runtime/debug"
8
+ "strings"
8
9
"sync"
9
10
"time"
10
11
@@ -106,7 +107,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
106
107
// The CORS library handles all other requests.
107
108
108
109
// Tell the user the allowed methods, and return.
109
- setAllowedHeaders (w , h .cfg .AllowGet )
110
+ setAllowHeader (w , h .cfg .AllowGet )
110
111
w .WriteHeader (http .StatusNoContent )
111
112
return
112
113
case http .MethodPost :
@@ -116,7 +117,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
116
117
}
117
118
fallthrough
118
119
default :
119
- setAllowedHeaders (w , h .cfg .AllowGet )
120
+ setAllowHeader (w , h .cfg .AllowGet )
120
121
http .Error (w , "405 - Method Not Allowed" , http .StatusMethodNotAllowed )
121
122
log .Warnf ("The IPFS API does not support %s requests." , r .Method )
122
123
return
@@ -191,11 +192,10 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
191
192
h .root .Call (req , re , h .env )
192
193
}
193
194
194
- func setAllowedHeaders (w http.ResponseWriter , allowGet bool ) {
195
- w .Header ().Add ("Allow" , http .MethodHead )
196
- w .Header ().Add ("Allow" , http .MethodOptions )
197
- w .Header ().Add ("Allow" , http .MethodPost )
195
+ func setAllowHeader (w http.ResponseWriter , allowGet bool ) {
196
+ allowedMethods := []string {http .MethodOptions , http .MethodPost }
198
197
if allowGet {
199
- w . Header (). Add ( "Allow" , http .MethodGet )
198
+ allowedMethods = append ( allowedMethods , http . MethodHead , http .MethodGet )
200
199
}
200
+ w .Header ().Set ("Allow" , strings .Join (allowedMethods , ", " ))
201
201
}
0 commit comments