17989: Reduces the manifest size limit so that it doesn't fail on extreme cases
[arvados.git] / lib / controller / router / router.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package router
6
7 import (
8         "context"
9         "fmt"
10         "math"
11         "net/http"
12         "strings"
13
14         "git.arvados.org/arvados.git/lib/controller/api"
15         "git.arvados.org/arvados.git/sdk/go/arvados"
16         "git.arvados.org/arvados.git/sdk/go/auth"
17         "git.arvados.org/arvados.git/sdk/go/ctxlog"
18         "git.arvados.org/arvados.git/sdk/go/httpserver"
19         "github.com/gorilla/mux"
20         "github.com/sirupsen/logrus"
21 )
22
23 type router struct {
24         mux     *mux.Router
25         backend arvados.API
26         config  Config
27 }
28
29 type Config struct {
30         // Return an error if request body exceeds this size. 0 means
31         // unlimited.
32         MaxRequestSize int
33
34         // If wrapCalls is not nil, it is called once for each API
35         // method, and the returned method is used in its place. This
36         // can be used to install hooks before and after each API call
37         // and alter responses; see localdb.WrapCallsInTransaction for
38         // an example.
39         WrapCalls func(api.RoutableFunc) api.RoutableFunc
40 }
41
42 // New returns a new router (which implements the http.Handler
43 // interface) that serves requests by calling Arvados API methods on
44 // the given backend.
45 func New(backend arvados.API, config Config) *router {
46         rtr := &router{
47                 mux:     mux.NewRouter(),
48                 backend: backend,
49                 config:  config,
50         }
51         rtr.addRoutes()
52         return rtr
53 }
54
55 func (rtr *router) addRoutes() {
56         for _, route := range []struct {
57                 endpoint    arvados.APIEndpoint
58                 defaultOpts func() interface{}
59                 exec        api.RoutableFunc
60         }{
61                 {
62                         arvados.EndpointConfigGet,
63                         func() interface{} { return &struct{}{} },
64                         func(ctx context.Context, opts interface{}) (interface{}, error) {
65                                 return rtr.backend.ConfigGet(ctx)
66                         },
67                 },
68                 {
69                         arvados.EndpointLogin,
70                         func() interface{} { return &arvados.LoginOptions{} },
71                         func(ctx context.Context, opts interface{}) (interface{}, error) {
72                                 return rtr.backend.Login(ctx, *opts.(*arvados.LoginOptions))
73                         },
74                 },
75                 {
76                         arvados.EndpointLogout,
77                         func() interface{} { return &arvados.LogoutOptions{} },
78                         func(ctx context.Context, opts interface{}) (interface{}, error) {
79                                 return rtr.backend.Logout(ctx, *opts.(*arvados.LogoutOptions))
80                         },
81                 },
82                 {
83                         arvados.EndpointCollectionCreate,
84                         func() interface{} { return &arvados.CreateOptions{} },
85                         func(ctx context.Context, opts interface{}) (interface{}, error) {
86                                 return rtr.backend.CollectionCreate(ctx, *opts.(*arvados.CreateOptions))
87                         },
88                 },
89                 {
90                         arvados.EndpointCollectionUpdate,
91                         func() interface{} { return &arvados.UpdateOptions{} },
92                         func(ctx context.Context, opts interface{}) (interface{}, error) {
93                                 return rtr.backend.CollectionUpdate(ctx, *opts.(*arvados.UpdateOptions))
94                         },
95                 },
96                 {
97                         arvados.EndpointCollectionGet,
98                         func() interface{} { return &arvados.GetOptions{} },
99                         func(ctx context.Context, opts interface{}) (interface{}, error) {
100                                 return rtr.backend.CollectionGet(ctx, *opts.(*arvados.GetOptions))
101                         },
102                 },
103                 {
104                         arvados.EndpointCollectionList,
105                         func() interface{} { return &arvados.ListOptions{Limit: -1} },
106                         func(ctx context.Context, opts interface{}) (interface{}, error) {
107                                 return rtr.backend.CollectionList(ctx, *opts.(*arvados.ListOptions))
108                         },
109                 },
110                 {
111                         arvados.EndpointCollectionProvenance,
112                         func() interface{} { return &arvados.GetOptions{} },
113                         func(ctx context.Context, opts interface{}) (interface{}, error) {
114                                 return rtr.backend.CollectionProvenance(ctx, *opts.(*arvados.GetOptions))
115                         },
116                 },
117                 {
118                         arvados.EndpointCollectionUsedBy,
119                         func() interface{} { return &arvados.GetOptions{} },
120                         func(ctx context.Context, opts interface{}) (interface{}, error) {
121                                 return rtr.backend.CollectionUsedBy(ctx, *opts.(*arvados.GetOptions))
122                         },
123                 },
124                 {
125                         arvados.EndpointCollectionDelete,
126                         func() interface{} { return &arvados.DeleteOptions{} },
127                         func(ctx context.Context, opts interface{}) (interface{}, error) {
128                                 return rtr.backend.CollectionDelete(ctx, *opts.(*arvados.DeleteOptions))
129                         },
130                 },
131                 {
132                         arvados.EndpointCollectionTrash,
133                         func() interface{} { return &arvados.DeleteOptions{} },
134                         func(ctx context.Context, opts interface{}) (interface{}, error) {
135                                 return rtr.backend.CollectionTrash(ctx, *opts.(*arvados.DeleteOptions))
136                         },
137                 },
138                 {
139                         arvados.EndpointCollectionUntrash,
140                         func() interface{} { return &arvados.UntrashOptions{} },
141                         func(ctx context.Context, opts interface{}) (interface{}, error) {
142                                 return rtr.backend.CollectionUntrash(ctx, *opts.(*arvados.UntrashOptions))
143                         },
144                 },
145                 {
146                         arvados.EndpointContainerCreate,
147                         func() interface{} { return &arvados.CreateOptions{} },
148                         func(ctx context.Context, opts interface{}) (interface{}, error) {
149                                 return rtr.backend.ContainerCreate(ctx, *opts.(*arvados.CreateOptions))
150                         },
151                 },
152                 {
153                         arvados.EndpointContainerUpdate,
154                         func() interface{} { return &arvados.UpdateOptions{} },
155                         func(ctx context.Context, opts interface{}) (interface{}, error) {
156                                 return rtr.backend.ContainerUpdate(ctx, *opts.(*arvados.UpdateOptions))
157                         },
158                 },
159                 {
160                         arvados.EndpointContainerGet,
161                         func() interface{} { return &arvados.GetOptions{} },
162                         func(ctx context.Context, opts interface{}) (interface{}, error) {
163                                 return rtr.backend.ContainerGet(ctx, *opts.(*arvados.GetOptions))
164                         },
165                 },
166                 {
167                         arvados.EndpointContainerList,
168                         func() interface{} { return &arvados.ListOptions{Limit: -1} },
169                         func(ctx context.Context, opts interface{}) (interface{}, error) {
170                                 return rtr.backend.ContainerList(ctx, *opts.(*arvados.ListOptions))
171                         },
172                 },
173                 {
174                         arvados.EndpointContainerDelete,
175                         func() interface{} { return &arvados.DeleteOptions{} },
176                         func(ctx context.Context, opts interface{}) (interface{}, error) {
177                                 return rtr.backend.ContainerDelete(ctx, *opts.(*arvados.DeleteOptions))
178                         },
179                 },
180                 {
181                         arvados.EndpointContainerRequestCreate,
182                         func() interface{} { return &arvados.CreateOptions{} },
183                         func(ctx context.Context, opts interface{}) (interface{}, error) {
184                                 return rtr.backend.ContainerRequestCreate(ctx, *opts.(*arvados.CreateOptions))
185                         },
186                 },
187                 {
188                         arvados.EndpointContainerRequestUpdate,
189                         func() interface{} { return &arvados.UpdateOptions{} },
190                         func(ctx context.Context, opts interface{}) (interface{}, error) {
191                                 return rtr.backend.ContainerRequestUpdate(ctx, *opts.(*arvados.UpdateOptions))
192                         },
193                 },
194                 {
195                         arvados.EndpointContainerRequestGet,
196                         func() interface{} { return &arvados.GetOptions{} },
197                         func(ctx context.Context, opts interface{}) (interface{}, error) {
198                                 return rtr.backend.ContainerRequestGet(ctx, *opts.(*arvados.GetOptions))
199                         },
200                 },
201                 {
202                         arvados.EndpointContainerRequestList,
203                         func() interface{} { return &arvados.ListOptions{Limit: -1} },
204                         func(ctx context.Context, opts interface{}) (interface{}, error) {
205                                 return rtr.backend.ContainerRequestList(ctx, *opts.(*arvados.ListOptions))
206                         },
207                 },
208                 {
209                         arvados.EndpointContainerRequestDelete,
210                         func() interface{} { return &arvados.DeleteOptions{} },
211                         func(ctx context.Context, opts interface{}) (interface{}, error) {
212                                 return rtr.backend.ContainerRequestDelete(ctx, *opts.(*arvados.DeleteOptions))
213                         },
214                 },
215                 {
216                         arvados.EndpointContainerLock,
217                         func() interface{} {
218                                 return &arvados.GetOptions{Select: []string{"uuid", "state", "priority", "auth_uuid", "locked_by_uuid"}}
219                         },
220                         func(ctx context.Context, opts interface{}) (interface{}, error) {
221                                 return rtr.backend.ContainerLock(ctx, *opts.(*arvados.GetOptions))
222                         },
223                 },
224                 {
225                         arvados.EndpointContainerUnlock,
226                         func() interface{} {
227                                 return &arvados.GetOptions{Select: []string{"uuid", "state", "priority", "auth_uuid", "locked_by_uuid"}}
228                         },
229                         func(ctx context.Context, opts interface{}) (interface{}, error) {
230                                 return rtr.backend.ContainerUnlock(ctx, *opts.(*arvados.GetOptions))
231                         },
232                 },
233                 {
234                         arvados.EndpointContainerSSH,
235                         func() interface{} { return &arvados.ContainerSSHOptions{} },
236                         func(ctx context.Context, opts interface{}) (interface{}, error) {
237                                 return rtr.backend.ContainerSSH(ctx, *opts.(*arvados.ContainerSSHOptions))
238                         },
239                 },
240                 {
241                         arvados.EndpointGroupCreate,
242                         func() interface{} { return &arvados.CreateOptions{} },
243                         func(ctx context.Context, opts interface{}) (interface{}, error) {
244                                 return rtr.backend.GroupCreate(ctx, *opts.(*arvados.CreateOptions))
245                         },
246                 },
247                 {
248                         arvados.EndpointGroupUpdate,
249                         func() interface{} { return &arvados.UpdateOptions{} },
250                         func(ctx context.Context, opts interface{}) (interface{}, error) {
251                                 return rtr.backend.GroupUpdate(ctx, *opts.(*arvados.UpdateOptions))
252                         },
253                 },
254                 {
255                         arvados.EndpointGroupList,
256                         func() interface{} { return &arvados.ListOptions{Limit: -1} },
257                         func(ctx context.Context, opts interface{}) (interface{}, error) {
258                                 return rtr.backend.GroupList(ctx, *opts.(*arvados.ListOptions))
259                         },
260                 },
261                 {
262                         arvados.EndpointGroupContents,
263                         func() interface{} { return &arvados.GroupContentsOptions{Limit: -1} },
264                         func(ctx context.Context, opts interface{}) (interface{}, error) {
265                                 return rtr.backend.GroupContents(ctx, *opts.(*arvados.GroupContentsOptions))
266                         },
267                 },
268                 {
269                         arvados.EndpointGroupContentsUUIDInPath,
270                         func() interface{} { return &arvados.GroupContentsOptions{Limit: -1} },
271                         func(ctx context.Context, opts interface{}) (interface{}, error) {
272                                 return rtr.backend.GroupContents(ctx, *opts.(*arvados.GroupContentsOptions))
273                         },
274                 },
275                 {
276                         arvados.EndpointGroupShared,
277                         func() interface{} { return &arvados.ListOptions{Limit: -1} },
278                         func(ctx context.Context, opts interface{}) (interface{}, error) {
279                                 return rtr.backend.GroupShared(ctx, *opts.(*arvados.ListOptions))
280                         },
281                 },
282                 {
283                         arvados.EndpointGroupGet,
284                         func() interface{} { return &arvados.GetOptions{} },
285                         func(ctx context.Context, opts interface{}) (interface{}, error) {
286                                 return rtr.backend.GroupGet(ctx, *opts.(*arvados.GetOptions))
287                         },
288                 },
289                 {
290                         arvados.EndpointGroupDelete,
291                         func() interface{} { return &arvados.DeleteOptions{} },
292                         func(ctx context.Context, opts interface{}) (interface{}, error) {
293                                 return rtr.backend.GroupDelete(ctx, *opts.(*arvados.DeleteOptions))
294                         },
295                 },
296                 {
297                         arvados.EndpointGroupTrash,
298                         func() interface{} { return &arvados.DeleteOptions{} },
299                         func(ctx context.Context, opts interface{}) (interface{}, error) {
300                                 return rtr.backend.GroupTrash(ctx, *opts.(*arvados.DeleteOptions))
301                         },
302                 },
303                 {
304                         arvados.EndpointGroupUntrash,
305                         func() interface{} { return &arvados.UntrashOptions{} },
306                         func(ctx context.Context, opts interface{}) (interface{}, error) {
307                                 return rtr.backend.GroupUntrash(ctx, *opts.(*arvados.UntrashOptions))
308                         },
309                 },
310                 {
311                         arvados.EndpointSpecimenCreate,
312                         func() interface{} { return &arvados.CreateOptions{} },
313                         func(ctx context.Context, opts interface{}) (interface{}, error) {
314                                 return rtr.backend.SpecimenCreate(ctx, *opts.(*arvados.CreateOptions))
315                         },
316                 },
317                 {
318                         arvados.EndpointSpecimenUpdate,
319                         func() interface{} { return &arvados.UpdateOptions{} },
320                         func(ctx context.Context, opts interface{}) (interface{}, error) {
321                                 return rtr.backend.SpecimenUpdate(ctx, *opts.(*arvados.UpdateOptions))
322                         },
323                 },
324                 {
325                         arvados.EndpointSpecimenGet,
326                         func() interface{} { return &arvados.GetOptions{} },
327                         func(ctx context.Context, opts interface{}) (interface{}, error) {
328                                 return rtr.backend.SpecimenGet(ctx, *opts.(*arvados.GetOptions))
329                         },
330                 },
331                 {
332                         arvados.EndpointSpecimenList,
333                         func() interface{} { return &arvados.ListOptions{Limit: -1} },
334                         func(ctx context.Context, opts interface{}) (interface{}, error) {
335                                 return rtr.backend.SpecimenList(ctx, *opts.(*arvados.ListOptions))
336                         },
337                 },
338                 {
339                         arvados.EndpointSpecimenDelete,
340                         func() interface{} { return &arvados.DeleteOptions{} },
341                         func(ctx context.Context, opts interface{}) (interface{}, error) {
342                                 return rtr.backend.SpecimenDelete(ctx, *opts.(*arvados.DeleteOptions))
343                         },
344                 },
345                 {
346                         arvados.EndpointUserCreate,
347                         func() interface{} { return &arvados.CreateOptions{} },
348                         func(ctx context.Context, opts interface{}) (interface{}, error) {
349                                 return rtr.backend.UserCreate(ctx, *opts.(*arvados.CreateOptions))
350                         },
351                 },
352                 {
353                         arvados.EndpointUserMerge,
354                         func() interface{} { return &arvados.UserMergeOptions{} },
355                         func(ctx context.Context, opts interface{}) (interface{}, error) {
356                                 return rtr.backend.UserMerge(ctx, *opts.(*arvados.UserMergeOptions))
357                         },
358                 },
359                 {
360                         arvados.EndpointUserActivate,
361                         func() interface{} { return &arvados.UserActivateOptions{} },
362                         func(ctx context.Context, opts interface{}) (interface{}, error) {
363                                 return rtr.backend.UserActivate(ctx, *opts.(*arvados.UserActivateOptions))
364                         },
365                 },
366                 {
367                         arvados.EndpointUserSetup,
368                         func() interface{} { return &arvados.UserSetupOptions{} },
369                         func(ctx context.Context, opts interface{}) (interface{}, error) {
370                                 return rtr.backend.UserSetup(ctx, *opts.(*arvados.UserSetupOptions))
371                         },
372                 },
373                 {
374                         arvados.EndpointUserUnsetup,
375                         func() interface{} { return &arvados.GetOptions{} },
376                         func(ctx context.Context, opts interface{}) (interface{}, error) {
377                                 return rtr.backend.UserUnsetup(ctx, *opts.(*arvados.GetOptions))
378                         },
379                 },
380                 {
381                         arvados.EndpointUserGetCurrent,
382                         func() interface{} { return &arvados.GetOptions{} },
383                         func(ctx context.Context, opts interface{}) (interface{}, error) {
384                                 return rtr.backend.UserGetCurrent(ctx, *opts.(*arvados.GetOptions))
385                         },
386                 },
387                 {
388                         arvados.EndpointUserGetSystem,
389                         func() interface{} { return &arvados.GetOptions{} },
390                         func(ctx context.Context, opts interface{}) (interface{}, error) {
391                                 return rtr.backend.UserGetSystem(ctx, *opts.(*arvados.GetOptions))
392                         },
393                 },
394                 {
395                         arvados.EndpointUserGet,
396                         func() interface{} { return &arvados.GetOptions{} },
397                         func(ctx context.Context, opts interface{}) (interface{}, error) {
398                                 return rtr.backend.UserGet(ctx, *opts.(*arvados.GetOptions))
399                         },
400                 },
401                 {
402                         arvados.EndpointUserUpdateUUID,
403                         func() interface{} { return &arvados.UpdateUUIDOptions{} },
404                         func(ctx context.Context, opts interface{}) (interface{}, error) {
405                                 return rtr.backend.UserUpdateUUID(ctx, *opts.(*arvados.UpdateUUIDOptions))
406                         },
407                 },
408                 {
409                         arvados.EndpointUserUpdate,
410                         func() interface{} { return &arvados.UpdateOptions{} },
411                         func(ctx context.Context, opts interface{}) (interface{}, error) {
412                                 return rtr.backend.UserUpdate(ctx, *opts.(*arvados.UpdateOptions))
413                         },
414                 },
415                 {
416                         arvados.EndpointUserList,
417                         func() interface{} { return &arvados.ListOptions{Limit: -1} },
418                         func(ctx context.Context, opts interface{}) (interface{}, error) {
419                                 return rtr.backend.UserList(ctx, *opts.(*arvados.ListOptions))
420                         },
421                 },
422                 {
423                         arvados.EndpointUserBatchUpdate,
424                         func() interface{} { return &arvados.UserBatchUpdateOptions{} },
425                         func(ctx context.Context, opts interface{}) (interface{}, error) {
426                                 return rtr.backend.UserBatchUpdate(ctx, *opts.(*arvados.UserBatchUpdateOptions))
427                         },
428                 },
429                 {
430                         arvados.EndpointUserDelete,
431                         func() interface{} { return &arvados.DeleteOptions{} },
432                         func(ctx context.Context, opts interface{}) (interface{}, error) {
433                                 return rtr.backend.UserDelete(ctx, *opts.(*arvados.DeleteOptions))
434                         },
435                 },
436                 {
437                         arvados.EndpointUserAuthenticate,
438                         func() interface{} { return &arvados.UserAuthenticateOptions{} },
439                         func(ctx context.Context, opts interface{}) (interface{}, error) {
440                                 return rtr.backend.UserAuthenticate(ctx, *opts.(*arvados.UserAuthenticateOptions))
441                         },
442                 },
443         } {
444                 exec := route.exec
445                 if rtr.config.WrapCalls != nil {
446                         exec = rtr.config.WrapCalls(exec)
447                 }
448                 rtr.addRoute(route.endpoint, route.defaultOpts, exec)
449         }
450         rtr.mux.NotFoundHandler = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
451                 httpserver.Errors(w, []string{"API endpoint not found"}, http.StatusNotFound)
452         })
453         rtr.mux.MethodNotAllowedHandler = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
454                 httpserver.Errors(w, []string{"API endpoint not found"}, http.StatusMethodNotAllowed)
455         })
456 }
457
458 var altMethod = map[string]string{
459         "PATCH": "PUT",  // Accept PUT as a synonym for PATCH
460         "GET":   "HEAD", // Accept HEAD at any GET route
461 }
462
463 func (rtr *router) addRoute(endpoint arvados.APIEndpoint, defaultOpts func() interface{}, exec api.RoutableFunc) {
464         methods := []string{endpoint.Method}
465         if alt, ok := altMethod[endpoint.Method]; ok {
466                 methods = append(methods, alt)
467         }
468         rtr.mux.Methods(methods...).Path("/" + endpoint.Path).HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
469                 logger := ctxlog.FromContext(req.Context())
470                 params, err := rtr.loadRequestParams(req, endpoint.AttrsKey)
471                 if err != nil {
472                         logger.WithFields(logrus.Fields{
473                                 "req":      req,
474                                 "method":   endpoint.Method,
475                                 "endpoint": endpoint,
476                         }).WithError(err).Debug("error loading request params")
477                         rtr.sendError(w, err)
478                         return
479                 }
480                 opts := defaultOpts()
481                 err = rtr.transcode(params, opts)
482                 if err != nil {
483                         logger.WithField("params", params).WithError(err).Debugf("error transcoding params to %T", opts)
484                         rtr.sendError(w, err)
485                         return
486                 }
487                 respOpts, err := rtr.responseOptions(opts)
488                 if err != nil {
489                         logger.WithField("opts", opts).WithError(err).Debugf("error getting response options from %T", opts)
490                         rtr.sendError(w, err)
491                         return
492                 }
493
494                 creds := auth.CredentialsFromRequest(req)
495                 err = creds.LoadTokensFromHTTPRequestBody(req)
496                 if err != nil {
497                         rtr.sendError(w, fmt.Errorf("error loading tokens from request body: %s", err))
498                         return
499                 }
500                 if rt, _ := params["reader_tokens"].([]interface{}); len(rt) > 0 {
501                         for _, t := range rt {
502                                 if t, ok := t.(string); ok {
503                                         creds.Tokens = append(creds.Tokens, t)
504                                 }
505                         }
506                 }
507                 ctx := auth.NewContext(req.Context(), creds)
508                 ctx = arvados.ContextWithRequestID(ctx, req.Header.Get("X-Request-Id"))
509                 logger.WithFields(logrus.Fields{
510                         "apiEndpoint": endpoint,
511                         "apiOptsType": fmt.Sprintf("%T", opts),
512                         "apiOpts":     opts,
513                 }).Debug("exec")
514                 resp, err := exec(ctx, opts)
515                 if err != nil {
516                         logger.WithError(err).Debugf("returning error type %T", err)
517                         rtr.sendError(w, err)
518                         return
519                 }
520                 rtr.sendResponse(w, req, resp, respOpts)
521         })
522 }
523
524 func (rtr *router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
525         switch strings.SplitN(strings.TrimLeft(r.URL.Path, "/"), "/", 2)[0] {
526         case "login", "logout", "auth":
527         default:
528                 w.Header().Set("Access-Control-Allow-Origin", "*")
529                 w.Header().Set("Access-Control-Allow-Methods", "GET, HEAD, PUT, POST, PATCH, DELETE")
530                 w.Header().Set("Access-Control-Allow-Headers", "Authorization, Content-Type, X-Http-Method-Override")
531                 w.Header().Set("Access-Control-Max-Age", "86486400")
532         }
533         if r.Method == "OPTIONS" {
534                 return
535         }
536         if r.Body != nil {
537                 // Wrap r.Body in a http.MaxBytesReader(), otherwise
538                 // r.ParseForm() uses a default max request body size
539                 // of 10 megabytes. Note we rely on the Nginx
540                 // configuration to enforce the real max body size.
541                 max := int64(rtr.config.MaxRequestSize)
542                 if max < 1 {
543                         max = math.MaxInt64 - 1
544                 }
545                 r.Body = http.MaxBytesReader(w, r.Body, max)
546         }
547         if r.Method == "POST" {
548                 err := r.ParseForm()
549                 if err != nil {
550                         if err.Error() == "http: request body too large" {
551                                 err = httpError(http.StatusRequestEntityTooLarge, err)
552                         }
553                         rtr.sendError(w, err)
554                         return
555                 }
556                 if m := r.FormValue("_method"); m != "" {
557                         r2 := *r
558                         r = &r2
559                         r.Method = m
560                 } else if m = r.Header.Get("X-Http-Method-Override"); m != "" {
561                         r2 := *r
562                         r = &r2
563                         r.Method = m
564                 }
565         }
566         rtr.mux.ServeHTTP(w, r)
567 }