summaryrefslogtreecommitdiff
path: root/internal/transport/finger.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2023-05-21 17:59:14 +0100
committerLibravatar GitHub <noreply@github.com>2023-05-21 18:59:14 +0200
commit2063d01cdb02c7ef26dc6d917e3bca252db5d5a8 (patch)
treeae220bc4956beb8bc09e3786f4ba8a0fb99b521b /internal/transport/finger.go
parent[feature] Make client IP logging configurable (#1799) (diff)
downloadgotosocial-0.9.0-rc2.tar.xz
[bugfix] Add back removed ValidateRequest() before backoff-retry loop (#1805)v0.9.0-rc2
* add back removed ValidateRequest() before backoff-retry loop Signed-off-by: kim <grufwub@gmail.com> * include response body in error response log Signed-off-by: kim <grufwub@gmail.com> * improved error response body draining Signed-off-by: kim <grufwub@gmail.com> * add more code commenting Signed-off-by: kim <grufwub@gmail.com> * move new error response logic to gtserror, handle instead in transport.Transport{} impl Signed-off-by: kim <grufwub@gmail.com> * appease ye oh mighty linter Signed-off-by: kim <grufwub@gmail.com> * fix mockhttpclient not setting request in http response Signed-off-by: kim <grufwub@gmail.com> --------- Signed-off-by: kim <grufwub@gmail.com>
Diffstat (limited to 'internal/transport/finger.go')
-rw-r--r--internal/transport/finger.go21
1 files changed, 12 insertions, 9 deletions
diff --git a/internal/transport/finger.go b/internal/transport/finger.go
index 18b028a64..e6086747b 100644
--- a/internal/transport/finger.go
+++ b/internal/transport/finger.go
@@ -27,6 +27,7 @@ import (
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
+ "github.com/superseriousbusiness/gotosocial/internal/gtserror"
)
// webfingerURLFor returns the URL to try a webfinger request against, as
@@ -105,14 +106,16 @@ func (t *transport) Finger(ctx context.Context, targetUsername string, targetDom
// From here on out, we're handling different failure scenarios and
// deciding whether we should do a host-meta based fallback or not
- if (rsp.StatusCode >= 500 && rsp.StatusCode < 600) || cached {
- // In case we got a 5xx, bail out irrespective of if the value
- // was cached or not. The target may be broken or be signalling
- // us to back-off.
- //
- // If it's any error but the URL was cached, bail out too
- return nil, fmt.Errorf("GET request to %s failed: %s", req.URL.String(), rsp.Status)
- }
+ // Response status codes >= 500 are returned as errors by the wrapped HTTP client.
+ //
+ // if (rsp.StatusCode >= 500 && rsp.StatusCode < 600) || cached {
+ // In case we got a 5xx, bail out irrespective of if the value
+ // was cached or not. The target may be broken or be signalling
+ // us to back-off.
+ //
+ // If it's any error but the URL was cached, bail out too
+ // return nil, gtserror.NewResponseError(rsp)
+ // }
// So far we've failed to get a successful response from the expected
// webfinger endpoint. Lets try and discover the webfinger endpoint
@@ -153,7 +156,7 @@ func (t *transport) Finger(ctx context.Context, targetUsername string, targetDom
}
// We've reached the end of the line here, both the original request
// and our attempt to resolve it through the fallback have failed
- return nil, fmt.Errorf("GET request to %s failed: %s", req.URL.String(), rsp.Status)
+ return nil, gtserror.NewResponseError(rsp)
}
// Set the URL in cache here, since host-meta told us this should be the