cleanup: merge httpheader and httpfailure into model (#758)
These two small packages could easily be merged into the model package, since they're clearly model-like packages. Part of https://github.com/ooni/probe/issues/2115
This commit is contained in:
@@ -15,7 +15,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/httpheader"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx/archival"
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
@@ -121,12 +120,12 @@ func (m Measurer) Run(
|
||||
return err
|
||||
}
|
||||
headers := map[string]string{
|
||||
randx.ChangeCapitalization("Accept"): httpheader.Accept(),
|
||||
randx.ChangeCapitalization("Accept"): model.HTTPHeaderAccept,
|
||||
randx.ChangeCapitalization("Accept-Charset"): "ISO-8859-1,utf-8;q=0.7,*;q=0.3",
|
||||
randx.ChangeCapitalization("Accept-Encoding"): "gzip,deflate,sdch",
|
||||
randx.ChangeCapitalization("Accept-Language"): httpheader.AcceptLanguage(),
|
||||
randx.ChangeCapitalization("Accept-Language"): model.HTTPHeaderAcceptLanguage,
|
||||
randx.ChangeCapitalization("Host"): randx.Letters(15) + ".com",
|
||||
randx.ChangeCapitalization("User-Agent"): httpheader.UserAgent(),
|
||||
randx.ChangeCapitalization("User-Agent"): model.HTTPHeaderUserAgent,
|
||||
}
|
||||
for key, value := range headers {
|
||||
// Implementation note: Golang will normalize the header names. We will use
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
"net/http/cookiejar"
|
||||
"net/url"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/httpheader"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx"
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
||||
"github.com/ooni/probe-cli/v3/internal/runtimex"
|
||||
)
|
||||
@@ -55,7 +55,7 @@ func (r Runner) Run(ctx context.Context) error {
|
||||
// returns httpheader.RandomUserAgent().
|
||||
func MaybeUserAgent(ua string) string {
|
||||
if ua == "" {
|
||||
ua = httpheader.UserAgent()
|
||||
ua = model.HTTPHeaderUserAgent
|
||||
}
|
||||
return ua
|
||||
}
|
||||
@@ -65,8 +65,8 @@ func (r Runner) httpGet(ctx context.Context, url string) error {
|
||||
req, err := http.NewRequest(r.Config.Method, url, nil)
|
||||
runtimex.PanicOnError(err, "http.NewRequest failed")
|
||||
req = req.WithContext(ctx)
|
||||
req.Header.Set("Accept", httpheader.Accept())
|
||||
req.Header.Set("Accept-Language", httpheader.AcceptLanguage())
|
||||
req.Header.Set("Accept", model.HTTPHeaderAccept)
|
||||
req.Header.Set("Accept-Language", model.HTTPHeaderAcceptLanguage)
|
||||
req.Header.Set("User-Agent", MaybeUserAgent(r.Config.UserAgent))
|
||||
if r.Config.HTTPHost != "" {
|
||||
req.Host = r.Config.HTTPHost
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/atomicx"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/httpheader"
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
)
|
||||
|
||||
func TestRunnerWithInvalidURLScheme(t *testing.T) {
|
||||
@@ -260,7 +260,7 @@ func TestRunnerWeCanForceUserAgent(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRunnerDefaultUserAgent(t *testing.T) {
|
||||
expected := httpheader.UserAgent()
|
||||
expected := model.HTTPHeaderUserAgent
|
||||
found := &atomicx.Int64{}
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Header.Get("User-Agent") == expected {
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/experiment/webconnectivity/internal"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/httpheader"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx/archival"
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
)
|
||||
@@ -174,9 +173,9 @@ func (m Measurer) Run(
|
||||
tk.Control, err = Control(ctx, sess, testhelper.Address, ControlRequest{
|
||||
HTTPRequest: URL.String(),
|
||||
HTTPRequestHeaders: map[string][]string{
|
||||
"Accept": {httpheader.Accept()},
|
||||
"Accept-Language": {httpheader.AcceptLanguage()},
|
||||
"User-Agent": {httpheader.UserAgent()},
|
||||
"Accept": {model.HTTPHeaderAccept},
|
||||
"Accept-Language": {model.HTTPHeaderAcceptLanguage},
|
||||
"User-Agent": {model.HTTPHeaderUserAgent},
|
||||
},
|
||||
TCPConnect: epnts.Endpoints(),
|
||||
})
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/internal/httpfailure"
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
"github.com/ooni/probe-cli/v3/internal/runtimex"
|
||||
)
|
||||
@@ -109,11 +108,11 @@ func (tk *TestKeys) Update(v urlgetter.MultiOutput) {
|
||||
if failure != nil {
|
||||
// nothing to do here
|
||||
} else if v.TestKeys.HTTPResponseStatus != 302 {
|
||||
failure = &httpfailure.UnexpectedStatusCode
|
||||
failure = &model.HTTPUnexpectedStatusCode
|
||||
} else if len(v.TestKeys.HTTPResponseLocations) != 1 {
|
||||
failure = &httpfailure.UnexpectedRedirectURL
|
||||
failure = &model.HTTPUnexpectedRedirectURL
|
||||
} else if v.TestKeys.HTTPResponseLocations[0] != WebHTTPSURL {
|
||||
failure = &httpfailure.UnexpectedRedirectURL
|
||||
failure = &model.HTTPUnexpectedRedirectURL
|
||||
}
|
||||
tk.WhatsappHTTPFailure = failure
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/ooni/probe-cli/v3/internal/atomicx"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/experiment/urlgetter"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/experiment/whatsapp"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/internal/httpfailure"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/mockable"
|
||||
"github.com/ooni/probe-cli/v3/internal/model"
|
||||
)
|
||||
@@ -414,7 +413,7 @@ func TestTestKeysOnlyWebHTTPFailureNo302(t *testing.T) {
|
||||
if tk.WhatsappEndpointsStatus != "ok" {
|
||||
t.Fatal("invalid WhatsappEndpointsStatus")
|
||||
}
|
||||
if *tk.WhatsappWebFailure != httpfailure.UnexpectedStatusCode {
|
||||
if *tk.WhatsappWebFailure != model.HTTPUnexpectedStatusCode {
|
||||
t.Fatal("invalid WhatsappWebFailure")
|
||||
}
|
||||
if tk.WhatsappWebStatus != "blocked" {
|
||||
@@ -459,7 +458,7 @@ func TestTestKeysOnlyWebHTTPFailureNoLocations(t *testing.T) {
|
||||
if tk.WhatsappEndpointsStatus != "ok" {
|
||||
t.Fatal("invalid WhatsappEndpointsStatus")
|
||||
}
|
||||
if *tk.WhatsappWebFailure != httpfailure.UnexpectedRedirectURL {
|
||||
if *tk.WhatsappWebFailure != model.HTTPUnexpectedRedirectURL {
|
||||
t.Fatal("invalid WhatsappWebFailure")
|
||||
}
|
||||
if tk.WhatsappWebStatus != "blocked" {
|
||||
@@ -504,7 +503,7 @@ func TestTestKeysOnlyWebHTTPFailureNotExpectedURL(t *testing.T) {
|
||||
if tk.WhatsappEndpointsStatus != "ok" {
|
||||
t.Fatal("invalid WhatsappEndpointsStatus")
|
||||
}
|
||||
if *tk.WhatsappWebFailure != httpfailure.UnexpectedRedirectURL {
|
||||
if *tk.WhatsappWebFailure != model.HTTPUnexpectedRedirectURL {
|
||||
t.Fatal("invalid WhatsappWebFailure")
|
||||
}
|
||||
if tk.WhatsappWebStatus != "blocked" {
|
||||
@@ -549,7 +548,7 @@ func TestTestKeysOnlyWebHTTPFailureTooManyURLs(t *testing.T) {
|
||||
if tk.WhatsappEndpointsStatus != "ok" {
|
||||
t.Fatal("invalid WhatsappEndpointsStatus")
|
||||
}
|
||||
if *tk.WhatsappWebFailure != httpfailure.UnexpectedRedirectURL {
|
||||
if *tk.WhatsappWebFailure != model.HTTPUnexpectedRedirectURL {
|
||||
t.Fatal("invalid WhatsappWebFailure")
|
||||
}
|
||||
if tk.WhatsappWebStatus != "blocked" {
|
||||
|
||||
Reference in New Issue
Block a user