Skip to content

net/http: invalid method strings #12078

Closed
@gdzx

Description

@gdzx

Hi.

Following the discussion at net/http: add method constants from RFC 2616 and net/http: HTTP methods check.

  1. What version of Go are you using (go version)?
    go version 1.4.2 linux/amd64
  2. What operating system and processor architecture are you using?
    Archlinux 4.1.4-1-ck cmd/cgo: fails with gcc 4.4.1 #1 SMP PREEMPT Mon Aug 3 16:56:11 EDT 2015 x86_64 GNU/Linux
  3. What did you do?
    req, err := http.NewRequest("GET ", url, nil), notice the extra space.
  4. What did you expect to see?
    An error as it is not a valid HTTP method.
  5. What did you see instead?
    For https://golang.org, the proper response for a GET request is send but it is inconsistent between servers. For instance, if we use " GET", some servers will respond with a bad request status.

It would also be useful to add the commonly used method constants to net/http from RFC 7231 along with PATCH from RFC 5789:

diff --git a/src/net/http/methods.go b/src/net/http/methods.go
new file mode 100644
index 0000000..3e8b18c
--- /dev/null
+++ b/src/net/http/methods.go
@@ -0,0 +1,21 @@
+// Copyright 2015 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package http
+
+// HTTP methods, defined in RFC 7231.
+const (
+       MethodHead   = "HEAD"
+       MethodGet    = "GET"
+       MethodPut    = "PUT"
+       MethodPost   = "POST"
+       MethodDelete = "DELETE"
+
+       MethodConnect = "CONNECT"
+       MethodOptions = "OPTIONS"
+       MethodTrace   = "TRACE"
+)
+
+// PATCH HTTP method, defined in RFC 5789.
+const MethodPatch = "PATCH"

Regards, sw.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions