LEFT | RIGHT |
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 512 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 } | 523 } |
524 | 524 |
525 // BasicAuth returns the username and password provided in the request's | 525 // BasicAuth returns the username and password provided in the request's |
526 // Authorization header, if the request uses HTTP Basic Authentication. | 526 // Authorization header, if the request uses HTTP Basic Authentication. |
527 // See RFC 2617, Section 2. | 527 // See RFC 2617, Section 2. |
528 func (r *Request) BasicAuth() (username, password string, ok bool) { | 528 func (r *Request) BasicAuth() (username, password string, ok bool) { |
529 auth := r.Header.Get("Authorization") | 529 auth := r.Header.Get("Authorization") |
530 if auth == "" { | 530 if auth == "" { |
531 return | 531 return |
532 } | 532 } |
533 » return ParseBasicAuth(auth) | 533 » return parseBasicAuth(auth) |
534 } | 534 } |
535 | 535 |
536 // ParseBasicAuth parses an HTTP Basic Authentication string. | 536 // parseBasicAuth parses an HTTP Basic Authentication string. |
537 // "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" returns ("Aladdin", "open sesame", true)
. | 537 // "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" returns ("Aladdin", "open sesame", true)
. |
538 func ParseBasicAuth(auth string) (username, password string, ok bool) { | 538 func parseBasicAuth(auth string) (username, password string, ok bool) { |
539 if !strings.HasPrefix(auth, "Basic ") { | 539 if !strings.HasPrefix(auth, "Basic ") { |
540 return | 540 return |
541 } | 541 } |
542 c, err := base64.StdEncoding.DecodeString(strings.TrimPrefix(auth, "Basi
c ")) | 542 c, err := base64.StdEncoding.DecodeString(strings.TrimPrefix(auth, "Basi
c ")) |
543 if err != nil { | 543 if err != nil { |
544 return | 544 return |
545 } | 545 } |
546 cs := string(c) | 546 cs := string(c) |
547 s := strings.IndexByte(cs, ':') | 547 s := strings.IndexByte(cs, ':') |
548 if s < 0 { | 548 if s < 0 { |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 | 911 |
912 func (r *Request) wantsClose() bool { | 912 func (r *Request) wantsClose() bool { |
913 return hasToken(r.Header.get("Connection"), "close") | 913 return hasToken(r.Header.get("Connection"), "close") |
914 } | 914 } |
915 | 915 |
916 func (r *Request) closeBody() { | 916 func (r *Request) closeBody() { |
917 if r.Body != nil { | 917 if r.Body != nil { |
918 r.Body.Close() | 918 r.Body.Close() |
919 } | 919 } |
920 } | 920 } |
LEFT | RIGHT |