mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-01-27 11:06:36 +01:00
small formatting changes (no logic)
This commit is contained in:
parent
5b765d734e
commit
5b5cbae476
4 changed files with 19 additions and 35 deletions
|
@ -178,6 +178,9 @@ func New(cfg Config) *Client {
|
||||||
return &c
|
return &c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RoundTrip allows httpclient.Client{} to be used as an http.Transport{}, just calling Client{}.Do().
|
||||||
|
func (c *Client) RoundTrip(r *http.Request) (rsp *http.Response, err error) { return c.Do(r) }
|
||||||
|
|
||||||
// Do will essentially perform http.Client{}.Do() with retry-backoff functionality.
|
// Do will essentially perform http.Client{}.Do() with retry-backoff functionality.
|
||||||
func (c *Client) Do(r *http.Request) (rsp *http.Response, err error) {
|
func (c *Client) Do(r *http.Request) (rsp *http.Response, err error) {
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,6 @@
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/filter/usermute"
|
"github.com/superseriousbusiness/gotosocial/internal/filter/usermute"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
"github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/httpclient"
|
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/log"
|
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/state"
|
"github.com/superseriousbusiness/gotosocial/internal/state"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/text"
|
"github.com/superseriousbusiness/gotosocial/internal/text"
|
||||||
|
@ -47,16 +46,6 @@ type realSender struct {
|
||||||
converter *typeutils.Converter
|
converter *typeutils.Converter
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRealSender creates a Sender from an http.Client instead of an httpclient.Client.
|
|
||||||
// This should only be used by NewSender and in tests.
|
|
||||||
func NewRealSender(httpClient *http.Client, state *state.State, converter *typeutils.Converter) Sender {
|
|
||||||
return &realSender{
|
|
||||||
httpClient: httpClient,
|
|
||||||
state: state,
|
|
||||||
converter: converter,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *realSender) Send(
|
func (r *realSender) Send(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
notification *gtsmodel.Notification,
|
notification *gtsmodel.Notification,
|
||||||
|
@ -329,13 +318,3 @@ func formatNotificationBody(apiNotification *apimodel.Notification) string {
|
||||||
func firstNBytesTrimSpace(s string, n int) string {
|
func firstNBytesTrimSpace(s string, n int) string {
|
||||||
return strings.TrimSpace(text.FirstNBytesByWords(strings.TrimSpace(s), n))
|
return strings.TrimSpace(text.FirstNBytesByWords(strings.TrimSpace(s), n))
|
||||||
}
|
}
|
||||||
|
|
||||||
// gtsHTTPClientRoundTripper helps wrap a GtS HTTP client back into a regular HTTP client,
|
|
||||||
// so that webpush-go can use our IP filters, bad hosts list, and retries.
|
|
||||||
type gtsHTTPClientRoundTripper struct {
|
|
||||||
httpClient *httpclient.Client
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *gtsHTTPClientRoundTripper) RoundTrip(request *http.Request) (*http.Response, error) {
|
|
||||||
return r.httpClient.Do(request)
|
|
||||||
}
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package webpush_test
|
package webpush
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -40,7 +40,6 @@
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/subscriptions"
|
"github.com/superseriousbusiness/gotosocial/internal/subscriptions"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/transport"
|
"github.com/superseriousbusiness/gotosocial/internal/transport"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
"github.com/superseriousbusiness/gotosocial/internal/typeutils"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/webpush"
|
|
||||||
"github.com/superseriousbusiness/gotosocial/testrig"
|
"github.com/superseriousbusiness/gotosocial/testrig"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -56,7 +55,7 @@ type RealSenderStandardTestSuite struct {
|
||||||
federator *federation.Federator
|
federator *federation.Federator
|
||||||
oauthServer oauth.Server
|
oauthServer oauth.Server
|
||||||
emailSender email.Sender
|
emailSender email.Sender
|
||||||
webPushSender webpush.Sender
|
webPushSender Sender
|
||||||
|
|
||||||
// standard suite models
|
// standard suite models
|
||||||
testTokens map[string]*gtsmodel.Token
|
testTokens map[string]*gtsmodel.Token
|
||||||
|
@ -120,13 +119,13 @@ func (suite *RealSenderStandardTestSuite) SetupTest() {
|
||||||
suite.oauthServer = testrig.NewTestOauthServer(suite.db)
|
suite.oauthServer = testrig.NewTestOauthServer(suite.db)
|
||||||
suite.emailSender = testrig.NewEmailSender("../../web/template/", nil)
|
suite.emailSender = testrig.NewEmailSender("../../web/template/", nil)
|
||||||
|
|
||||||
suite.webPushSender = webpush.NewRealSender(
|
suite.webPushSender = &realSender{
|
||||||
&http.Client{
|
&http.Client{
|
||||||
Transport: suite,
|
Transport: suite,
|
||||||
},
|
},
|
||||||
&suite.state,
|
&suite.state,
|
||||||
suite.typeconverter,
|
suite.typeconverter,
|
||||||
)
|
}
|
||||||
|
|
||||||
suite.processor = processing.NewProcessor(
|
suite.processor = processing.NewProcessor(
|
||||||
cleaner.New(&suite.state),
|
cleaner.New(&suite.state),
|
||||||
|
|
|
@ -41,14 +41,17 @@ type Sender interface {
|
||||||
|
|
||||||
// NewSender creates a new sender from an HTTP client, DB, and worker pool.
|
// NewSender creates a new sender from an HTTP client, DB, and worker pool.
|
||||||
func NewSender(httpClient *httpclient.Client, state *state.State, converter *typeutils.Converter) Sender {
|
func NewSender(httpClient *httpclient.Client, state *state.State, converter *typeutils.Converter) Sender {
|
||||||
return NewRealSender(
|
return &realSender{
|
||||||
&http.Client{
|
httpClient: &http.Client{
|
||||||
Transport: >sHTTPClientRoundTripper{
|
// Pass in our wrapped httpclient.Client{}
|
||||||
httpClient: httpClient,
|
// type as http.Transport{} in order to take
|
||||||
},
|
// advantage of retries, SSF protection etc.
|
||||||
// Other fields are already set on the http.Client inside the httpclient.Client.
|
Transport: httpClient,
|
||||||
|
|
||||||
|
// Other http.Client{} fields are already
|
||||||
|
// set in embedded httpclient.Client{}.
|
||||||
},
|
},
|
||||||
state,
|
state: state,
|
||||||
converter,
|
converter: converter,
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue