OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // HTTP Request reading and parsing. | 5 // HTTP Request reading and parsing. |
6 | 6 |
7 package http | 7 package http |
8 | 8 |
9 import ( | 9 import ( |
10 "bufio" | 10 "bufio" |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 return 0, 0, false | 417 return 0, 0, false |
418 } | 418 } |
419 minor, err = strconv.Atoi(vers[dot+1:]) | 419 minor, err = strconv.Atoi(vers[dot+1:]) |
420 if err != nil || minor < 0 || minor > Big { | 420 if err != nil || minor < 0 || minor > Big { |
421 return 0, 0, false | 421 return 0, 0, false |
422 } | 422 } |
423 return major, minor, true | 423 return major, minor, true |
424 } | 424 } |
425 | 425 |
426 // NewRequest returns a new Request given a method, URL, and optional body. | 426 // NewRequest returns a new Request given a method, URL, and optional body. |
| 427 // |
| 428 // If the provided body is also an io.Closer, the returned |
| 429 // Request.Body is set to body and will be closed by the Client |
| 430 // methods Do, Post, and PostForm, and Transport.RoundTrip. |
427 func NewRequest(method, urlStr string, body io.Reader) (*Request, error) { | 431 func NewRequest(method, urlStr string, body io.Reader) (*Request, error) { |
428 u, err := url.Parse(urlStr) | 432 u, err := url.Parse(urlStr) |
429 if err != nil { | 433 if err != nil { |
430 return nil, err | 434 return nil, err |
431 } | 435 } |
432 rc, ok := body.(io.ReadCloser) | 436 rc, ok := body.(io.ReadCloser) |
433 if !ok && body != nil { | 437 if !ok && body != nil { |
434 rc = ioutil.NopCloser(body) | 438 rc = ioutil.NopCloser(body) |
435 } | 439 } |
436 req := &Request{ | 440 req := &Request{ |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 func (r *Request) wantsHttp10KeepAlive() bool { | 841 func (r *Request) wantsHttp10KeepAlive() bool { |
838 if r.ProtoMajor != 1 || r.ProtoMinor != 0 { | 842 if r.ProtoMajor != 1 || r.ProtoMinor != 0 { |
839 return false | 843 return false |
840 } | 844 } |
841 return hasToken(r.Header.get("Connection"), "keep-alive") | 845 return hasToken(r.Header.get("Connection"), "keep-alive") |
842 } | 846 } |
843 | 847 |
844 func (r *Request) wantsClose() bool { | 848 func (r *Request) wantsClose() bool { |
845 return hasToken(r.Header.get("Connection"), "close") | 849 return hasToken(r.Header.get("Connection"), "close") |
846 } | 850 } |
OLD | NEW |