@@ -78,7 +78,8 @@ func (pr httpProber) Probe(req *http.Request, timeout time.Duration) (probe.Resu
78
78
Transport : pr .transport ,
79
79
CheckRedirect : RedirectChecker (pr .followNonLocalRedirects ),
80
80
}
81
- return DoHTTPProbe (req , client )
81
+ result , details , _ , err := DoHTTPProbe (req , client )
82
+ return result , details , err
82
83
}
83
84
84
85
// GetHTTPInterface is an interface for making HTTP requests, that returns a response and error.
@@ -90,36 +91,37 @@ type GetHTTPInterface interface {
90
91
// If the HTTP response code is successful (i.e. 400 > code >= 200), it returns Success.
91
92
// If the HTTP response code is unsuccessful or HTTP communication fails, it returns Failure.
92
93
// This is exported because some other packages may want to do direct HTTP probes.
93
- func DoHTTPProbe (req * http.Request , client GetHTTPInterface ) (probe.Result , string , error ) {
94
+ func DoHTTPProbe (req * http.Request , client GetHTTPInterface ) (probe.Result , string , string , error ) {
94
95
url := req .URL
95
96
headers := req .Header
96
97
res , err := client .Do (req )
97
98
if err != nil {
98
99
// Convert errors into failures to catch timeouts.
99
- return probe .Failure , err .Error (), nil
100
+ return probe .Failure , err .Error (), "" , nil
100
101
}
101
102
defer res .Body .Close ()
102
103
b , err := utilio .ReadAtMost (res .Body , maxRespBodyLength )
103
104
if err != nil {
104
105
if err == utilio .ErrLimitReached {
105
106
klog .V (4 ).Infof ("Non fatal body truncation for %s, Response: %v" , url .String (), * res )
106
107
} else {
107
- return probe .Failure , "" , err
108
+ return probe .Failure , "" , "" , err
108
109
}
109
110
}
110
111
body := string (b )
111
112
if res .StatusCode >= http .StatusOK && res .StatusCode < http .StatusBadRequest {
112
113
if res .StatusCode >= http .StatusMultipleChoices { // Redirect
113
114
klog .V (4 ).Infof ("Probe terminated redirects for %s, Response: %v" , url .String (), * res )
114
- return probe .Warning , fmt .Sprintf ("Probe terminated redirects, Response body: %v" , body ), nil
115
+ return probe .Warning , fmt .Sprintf ("Probe terminated redirects, Response body: %v" , body ), body , nil
115
116
}
116
117
klog .V (4 ).Infof ("Probe succeeded for %s, Response: %v" , url .String (), * res )
117
- return probe .Success , body , nil
118
+ return probe .Success , body , body , nil
118
119
}
119
120
klog .V (4 ).Infof ("Probe failed for %s with request headers %v, response body: %v" , url .String (), headers , body )
120
121
// Note: Until https://issue.k8s.io/99425 is addressed, this user-facing failure message must not contain the response body.
122
+ // @deads2k recommended we return the body. Slack discussion: https://redhat-internal.slack.com/archives/C04UQLWQAP3/p1679590747021409
121
123
failureMsg := fmt .Sprintf ("HTTP probe failed with statuscode: %d" , res .StatusCode )
122
- return probe .Failure , failureMsg , nil
124
+ return probe .Failure , failureMsg , body , nil
123
125
}
124
126
125
127
// RedirectChecker returns a function that can be used to check HTTP redirects.
0 commit comments