Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1975)

Delta Between Two Patch Sets: src/pkg/net/http/request.go

Issue 76540043: code review 76540043: net/http: add BasicAuth method to *http.Request
Left Patch Set: diff -r c37fc54f7e208062baa619ecc43197dff1448a2c https://code.google.com/p/go Created 9 years, 7 months ago
Right Patch Set: diff -r e5c87cefb57fffc5767209542be5c4e58123e3c6 https://code.google.com/p/go Created 9 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | src/pkg/net/http/request_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
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
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 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b