2ef5fb503a
* fix(webconnectivity): allow measuring https://1.1.1.1 There were two issues preventing us from doing so: 1. in netx, the address resolver was too later in the resolver chain. Therefore, its result wasn't added to the events. 2. when building the DNSCache (in httpget.go), we didn't consider the case where the input is an address. We need to treat this case specially to make sure there is no DNSCache. See https://github.com/ooni/probe/issues/1376. * fix: add unit tests for code making the dnscache * fix(netx): make sure all tests pass * chore: bump webconnectivity version
68 lines
1.9 KiB
Go
68 lines
1.9 KiB
Go
package webconnectivity
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net"
|
|
"net/url"
|
|
"strings"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter"
|
|
"github.com/ooni/probe-cli/v3/internal/engine/model"
|
|
)
|
|
|
|
// HTTPGetConfig contains the config for HTTPGet
|
|
type HTTPGetConfig struct {
|
|
Addresses []string
|
|
Session model.ExperimentSession
|
|
TargetURL *url.URL
|
|
}
|
|
|
|
// TODO(bassosimone): we should normalize the timings
|
|
|
|
// HTTPGetResult contains the results of HTTPGet
|
|
type HTTPGetResult struct {
|
|
TestKeys urlgetter.TestKeys
|
|
Failure *string
|
|
}
|
|
|
|
// TODO(bassosimone): Web Connectivity uses too much external testing
|
|
// and we should actually expose much less to the outside by using
|
|
// internal testing and by making _many_ functions private.
|
|
|
|
// HTTPGetMakeDNSCache constructs the DNSCache option for HTTPGet
|
|
// by combining domain and addresses into a single string. As a
|
|
// corner case, if the domain is an IP address, we return an empty
|
|
// string. This corner case corresponds to Web Connectivity
|
|
// inputs like https://1.1.1.1.
|
|
func HTTPGetMakeDNSCache(domain, addresses string) string {
|
|
if net.ParseIP(domain) != nil {
|
|
return ""
|
|
}
|
|
return fmt.Sprintf("%s %s", domain, addresses)
|
|
}
|
|
|
|
// HTTPGet performs the HTTP/HTTPS part of Web Connectivity.
|
|
func HTTPGet(ctx context.Context, config HTTPGetConfig) (out HTTPGetResult) {
|
|
addresses := strings.Join(config.Addresses, " ")
|
|
if addresses == "" {
|
|
// TODO(bassosimone): what to do in this case? We clearly
|
|
// cannot fill the DNS cache...
|
|
return
|
|
}
|
|
target := config.TargetURL.String()
|
|
config.Session.Logger().Infof("GET %s...", target)
|
|
domain := config.TargetURL.Hostname()
|
|
result, err := urlgetter.Getter{
|
|
Config: urlgetter.Config{
|
|
DNSCache: HTTPGetMakeDNSCache(domain, addresses),
|
|
},
|
|
Session: config.Session,
|
|
Target: target,
|
|
}.Get(ctx)
|
|
config.Session.Logger().Infof("GET %s... %+v", target, err)
|
|
out.Failure = result.Failure
|
|
out.TestKeys = result
|
|
return
|
|
}
|