MCPcopy
hub / github.com/gorilla/mux / newRequest

Function newRequest

mux_test.go:2958–2995  ·  mux_test.go::newRequest

newRequest is a helper function to create a new request with a method and url. The request returned is a 'server' request as opposed to a 'client' one through simulated write onto the wire and read off of the wire. The differences between requests are detailed in the net/http package.

(method, url string)

Source from the content-addressed store, hash-verified

2956// simulated write onto the wire and read off of the wire.
2957// The differences between requests are detailed in the net/http package.
2958func newRequest(method, url string) *http.Request {
2959 req, err := http.NewRequest(method, url, nil)
2960 if err != nil {
2961 panic(err)
2962 }
2963 // extract the escaped original host+path from url
2964 // http://localhost/path/here?v=1#frag -> //localhost/path/here
2965 opaque := ""
2966 if i := len(req.URL.Scheme); i > 0 {
2967 opaque = url[i+1:]
2968 }
2969
2970 if i := strings.LastIndex(opaque, "?"); i > -1 {
2971 opaque = opaque[:i]
2972 }
2973 if i := strings.LastIndex(opaque, "#"); i > -1 {
2974 opaque = opaque[:i]
2975 }
2976
2977 // Escaped host+path workaround as detailed in https://golang.org/pkg/net/url/#URL
2978 // for < 1.5 client side workaround
2979 req.URL.Opaque = opaque
2980
2981 // Simulate writing to wire
2982 var buff bytes.Buffer
2983 err = req.Write(&buff)
2984 if err != nil {
2985 log.Printf("Failed writing HTTP request: %v", err)
2986 }
2987 ioreader := bufio.NewReader(&buff)
2988
2989 // Parse request off of 'wire'
2990 req, err = http.ReadRequest(ioreader)
2991 if err != nil {
2992 panic(err)
2993 }
2994 return req
2995}
2996
2997// create a new request with the provided headers
2998func newRequestWithHeaders(method, url string, headers ...string) *http.Request {

Callers 15

TestMiddlewareFunction · 0.85
TestMiddlewareSubrouterFunction · 0.85
TestMiddlewareExecutionFunction · 0.85
TestMiddlewareNotFoundFunction · 0.85
TestCORSMethodMiddlewareFunction · 0.85
TestHostFunction · 0.85
TestPathFunction · 0.85

Calls 1

WriteMethod · 0.45

Tested by

no test coverage detected