Skip to content

Commit d760024

Browse files
authored
Intercept health check requests and return a 200 response (#143)
1 parent 6b6aae6 commit d760024

File tree

1 file changed

+23
-0
lines changed
  • tunnel/internal/client/ssh

1 file changed

+23
-0
lines changed

tunnel/internal/client/ssh/ssh.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,29 @@ func (s *SshClient) httpTunnel(src, dst net.Conn) {
198198
return
199199
}
200200

201+
// Early return for health check requests with a direct response
202+
if request.Header.Get("X-Portr-Ping-Request") == "true" {
203+
response := &http.Response{
204+
Status: "200 OK",
205+
StatusCode: 200,
206+
Proto: "HTTP/1.1",
207+
ProtoMajor: 1,
208+
ProtoMinor: 1,
209+
Header: http.Header{},
210+
Body: io.NopCloser(bytes.NewBufferString("")),
211+
}
212+
213+
err = response.Write(srcWriter)
214+
if err != nil {
215+
if s.config.Debug {
216+
log.Error("Failed to write health check response", "error", err)
217+
}
218+
return
219+
}
220+
srcWriter.Flush()
221+
return
222+
}
223+
201224
// read and replace request body
202225
requestBody, err := io.ReadAll(request.Body)
203226
if err != nil {

0 commit comments

Comments
 (0)