@@ -76,7 +76,8 @@ func (pr httpProber) Probe(url *url.URL, headers http.Header, timeout time.Durat
76
76
Transport : pr .transport ,
77
77
CheckRedirect : redirectChecker (pr .followNonLocalRedirects ),
78
78
}
79
- return DoHTTPProbe (url , headers , client )
79
+ result , details , _ , err := DoHTTPProbe (url , headers , client )
80
+ return result , details , err
80
81
}
81
82
82
83
// GetHTTPInterface is an interface for making HTTP requests, that returns a response and error.
@@ -88,11 +89,11 @@ type GetHTTPInterface interface {
88
89
// If the HTTP response code is successful (i.e. 400 > code >= 200), it returns Success.
89
90
// If the HTTP response code is unsuccessful or HTTP communication fails, it returns Failure.
90
91
// This is exported because some other packages may want to do direct HTTP probes.
91
- func DoHTTPProbe (url * url.URL , headers http.Header , client GetHTTPInterface ) (probe.Result , string , error ) {
92
+ func DoHTTPProbe (url * url.URL , headers http.Header , client GetHTTPInterface ) (probe.Result , string , string , error ) {
92
93
req , err := http .NewRequest ("GET" , url .String (), nil )
93
94
if err != nil {
94
95
// Convert errors into failures to catch timeouts.
95
- return probe .Failure , err .Error (), nil
96
+ return probe .Failure , err .Error (), "" , nil
96
97
}
97
98
if _ , ok := headers ["User-Agent" ]; ! ok {
98
99
if headers == nil {
@@ -114,28 +115,28 @@ func DoHTTPProbe(url *url.URL, headers http.Header, client GetHTTPInterface) (pr
114
115
res , err := client .Do (req )
115
116
if err != nil {
116
117
// Convert errors into failures to catch timeouts.
117
- return probe .Failure , err .Error (), nil
118
+ return probe .Failure , err .Error (), "" , nil
118
119
}
119
120
defer res .Body .Close ()
120
121
b , err := utilio .ReadAtMost (res .Body , maxRespBodyLength )
121
122
if err != nil {
122
123
if err == utilio .ErrLimitReached {
123
124
klog .V (4 ).Infof ("Non fatal body truncation for %s, Response: %v" , url .String (), * res )
124
125
} else {
125
- return probe .Failure , "" , err
126
+ return probe .Failure , "" , "" , err
126
127
}
127
128
}
128
129
body := string (b )
129
130
if res .StatusCode >= http .StatusOK && res .StatusCode < http .StatusBadRequest {
130
131
if res .StatusCode >= http .StatusMultipleChoices { // Redirect
131
132
klog .V (4 ).Infof ("Probe terminated redirects for %s, Response: %v" , url .String (), * res )
132
- return probe .Warning , body , nil
133
+ return probe .Warning , body , body , nil
133
134
}
134
135
klog .V (4 ).Infof ("Probe succeeded for %s, Response: %v" , url .String (), * res )
135
- return probe .Success , body , nil
136
+ return probe .Success , body , body , nil
136
137
}
137
138
klog .V (4 ).Infof ("Probe failed for %s with request headers %v, response body: %v" , url .String (), headers , body )
138
- return probe .Failure , fmt .Sprintf ("HTTP probe failed with statuscode: %d" , res .StatusCode ), nil
139
+ return probe .Failure , fmt .Sprintf ("HTTP probe failed with statuscode: %d" , res .StatusCode ), body , nil
139
140
}
140
141
141
142
func redirectChecker (followNonLocalRedirects bool ) func (* http.Request , []* http.Request ) error {
0 commit comments