瀏覽代碼

Merge pull request #85 from rauls5382/tls

Merge commits from Go distribution
Raul Silvera 8 年之前
父節點
當前提交
2d6d840df8
共有 2 個檔案被更改,包括 42 行新增28 行删除
  1. 19
    3
      internal/driver/fetch.go
  2. 23
    25
      profile/legacy_profile.go

+ 19
- 3
internal/driver/fetch.go 查看文件

16
 
16
 
17
 import (
17
 import (
18
 	"bytes"
18
 	"bytes"
19
+	"crypto/tls"
19
 	"fmt"
20
 	"fmt"
20
 	"io"
21
 	"io"
21
 	"io/ioutil"
22
 	"io/ioutil"
487
 
488
 
488
 // httpGet is a wrapper around http.Get; it is defined as a variable
489
 // httpGet is a wrapper around http.Get; it is defined as a variable
489
 // so it can be redefined during for testing.
490
 // so it can be redefined during for testing.
490
-var httpGet = func(url string, timeout time.Duration) (*http.Response, error) {
491
+var httpGet = func(source string, timeout time.Duration) (*http.Response, error) {
492
+	url, err := url.Parse(source)
493
+	if err != nil {
494
+		return nil, err
495
+	}
496
+
497
+	var tlsConfig *tls.Config
498
+	if url.Scheme == "https+insecure" {
499
+		tlsConfig = &tls.Config{
500
+			InsecureSkipVerify: true,
501
+		}
502
+		url.Scheme = "https"
503
+		source = url.String()
504
+	}
505
+
491
 	client := &http.Client{
506
 	client := &http.Client{
492
 		Transport: &http.Transport{
507
 		Transport: &http.Transport{
493
 			ResponseHeaderTimeout: timeout + 5*time.Second,
508
 			ResponseHeaderTimeout: timeout + 5*time.Second,
494
-			Proxy: http.ProxyFromEnvironment,
509
+			Proxy:           http.ProxyFromEnvironment,
510
+			TLSClientConfig: tlsConfig,
495
 		},
511
 		},
496
 	}
512
 	}
497
-	return client.Get(url)
513
+	return client.Get(source)
498
 }
514
 }

+ 23
- 25
profile/legacy_profile.go 查看文件

710
 	const delimiter = "="
710
 	const delimiter = "="
711
 	for s.Scan() {
711
 	for s.Scan() {
712
 		line := s.Text()
712
 		line := s.Text()
713
-
714
-		if line = strings.TrimSpace(line); line == "" {
713
+		if line = strings.TrimSpace(line); isSpaceOrComment(line) {
715
 			continue
714
 			continue
716
 		}
715
 		}
717
-
718
 		if strings.HasPrefix(line, "---") {
716
 		if strings.HasPrefix(line, "---") {
719
 			break
717
 			break
720
 		}
718
 		}
721
-
722
 		attr := strings.SplitN(line, delimiter, 2)
719
 		attr := strings.SplitN(line, delimiter, 2)
723
 		if len(attr) != 2 {
720
 		if len(attr) != 2 {
724
 			break
721
 			break
761
 		if strings.HasPrefix(line, "---") {
758
 		if strings.HasPrefix(line, "---") {
762
 			break
759
 			break
763
 		}
760
 		}
764
-		value, addrs, err := parseContentionSample(line, p.Period, cpuHz)
765
-		if err != nil {
766
-			return nil, err
767
-		}
768
-		var sloc []*Location
769
-		for _, addr := range addrs {
770
-			// Addresses from stack traces point to the next instruction after
771
-			// each call. Adjust by -1 to land somewhere on the actual call.
772
-			addr--
773
-			loc := locs[addr]
774
-			if locs[addr] == nil {
775
-				loc = &Location{
776
-					Address: addr,
761
+		if !isSpaceOrComment(line) {
762
+			value, addrs, err := parseContentionSample(line, p.Period, cpuHz)
763
+			if err != nil {
764
+				return nil, err
765
+			}
766
+			var sloc []*Location
767
+			for _, addr := range addrs {
768
+				// Addresses from stack traces point to the next instruction after
769
+				// each call. Adjust by -1 to land somewhere on the actual call.
770
+				addr--
771
+				loc := locs[addr]
772
+				if locs[addr] == nil {
773
+					loc = &Location{
774
+						Address: addr,
775
+					}
776
+					p.Location = append(p.Location, loc)
777
+					locs[addr] = loc
777
 				}
778
 				}
778
-				p.Location = append(p.Location, loc)
779
-				locs[addr] = loc
779
+				sloc = append(sloc, loc)
780
 			}
780
 			}
781
-			sloc = append(sloc, loc)
781
+			p.Sample = append(p.Sample, &Sample{
782
+				Value:    value,
783
+				Location: sloc,
784
+			})
782
 		}
785
 		}
783
-		p.Sample = append(p.Sample, &Sample{
784
-			Value:    value,
785
-			Location: sloc,
786
-		})
787
-
788
 		if !s.Scan() {
786
 		if !s.Scan() {
789
 			break
787
 			break
790
 		}
788
 		}