mirror of
https://github.com/owncloud/ocis
synced 2026-04-25 17:25:21 +02:00
On IPv6-only deployment I encountered two problem with collaboration service and CheckHandler: * getOutBoundIP() did not allow IPv6 addresses to be used as outbound * FailSaveAddress() did double interpolation of the "::" literal on GUA IPv6 addresses containing "::"
42 lines
823 B
Go
42 lines
823 B
Go
package checks
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/owncloud/ocis/v2/ocis-pkg/handlers"
|
|
)
|
|
|
|
// NewHTTPCheck checks the reachability of a http server.
|
|
func NewHTTPCheck(rawUrl string) func(context.Context) error {
|
|
return func(_ context.Context) error {
|
|
if !strings.HasPrefix(rawUrl, "http://") && !strings.HasPrefix(rawUrl, "https://") {
|
|
rawUrl = "http://" + rawUrl
|
|
}
|
|
|
|
parsedUrl, err := url.Parse(rawUrl)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
parsedUrl.Host, err = handlers.FailSaveAddress(parsedUrl.Host)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
c := http.Client{
|
|
Timeout: 3 * time.Second,
|
|
}
|
|
resp, err := c.Get(parsedUrl.String())
|
|
if err != nil {
|
|
return fmt.Errorf("could not connect to http server: %v", err)
|
|
}
|
|
_ = resp.Body.Close()
|
|
return nil
|
|
}
|
|
}
|