src/net/http/fs.go | 20 +++++--------------- src/net/http/fs_test.go | 41 ----------------------------------------- diff --git a/src/net/http/fs.go b/src/net/http/fs.go index 83459046bf76eab7e1c487b4e6c59de36902d6ed..41e0b43ac819bfdc22e78079fadaa6aa26813214 100644 --- a/src/net/http/fs.go +++ b/src/net/http/fs.go @@ -858,22 +858,12 @@ return &fileHandler{root} } func (f *fileHandler) ServeHTTP(w ResponseWriter, r *Request) { - const options = MethodOptions + ", " + MethodGet + ", " + MethodHead - - switch r.Method { - case MethodGet, MethodHead: - if !strings.HasPrefix(r.URL.Path, "/") { - r.URL.Path = "/" + r.URL.Path - } - serveFile(w, r, f.root, path.Clean(r.URL.Path), true) - - case MethodOptions: - w.Header().Set("Allow", options) - - default: - w.Header().Set("Allow", options) - Error(w, "read-only", StatusMethodNotAllowed) + upath := r.URL.Path + if !strings.HasPrefix(upath, "/") { + upath = "/" + upath + r.URL.Path = upath } + serveFile(w, r, f.root, path.Clean(upath), true) } // httpRange specifies the byte range to be sent to the client. diff --git a/src/net/http/fs_test.go b/src/net/http/fs_test.go index 74f7a80e279e53def134a268d405613ba3a9a3c3..e25a580b1fada446b4d672c8d94aa778afcc3e79 100644 --- a/src/net/http/fs_test.go +++ b/src/net/http/fs_test.go @@ -24,7 +24,6 @@ "path/filepath" "reflect" "regexp" "runtime" - "sort" "strings" "testing" "time" @@ -417,46 +416,6 @@ t.Logf("expected a directory listing with foo.txt, got %q", s) } if s := get("/bar/foo.txt"); s != "Hello world" { t.Logf("expected %q, got %q", "Hello world", s) - } -} - -func TestFileServerMethodOptions(t *testing.T) { run(t, testFileServerMethodOptions) } -func testFileServerMethodOptions(t *testing.T, mode testMode) { - const want = "GET, HEAD, OPTIONS" - ts := newClientServerTest(t, mode, FileServer(Dir("."))).ts - - tests := []struct { - method string - wantStatus int - }{ - {MethodOptions, StatusOK}, - - {MethodDelete, StatusMethodNotAllowed}, - {MethodPut, StatusMethodNotAllowed}, - {MethodPost, StatusMethodNotAllowed}, - } - - for _, test := range tests { - req, err := NewRequest(test.method, ts.URL, nil) - if err != nil { - t.Fatal(err) - } - res, err := ts.Client().Do(req) - if err != nil { - t.Fatal(err) - } - defer res.Body.Close() - - if res.StatusCode != test.wantStatus { - t.Errorf("%s got status %q, want code %d", test.method, res.Status, test.wantStatus) - } - - a := strings.Split(res.Header.Get("Allow"), ", ") - sort.Strings(a) - got := strings.Join(a, ", ") - if got != want { - t.Errorf("%s got Allow header %q, want %q", test.method, got, want) - } } }