Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow custom http.Client #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions rtorrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"log"
"net/http"
"time"

"github.com/autobrr/go-rtorrent/xmlrpc"
Expand Down Expand Up @@ -51,6 +52,12 @@ func NewClient(cfg Config) *Client {
return c
}

// WithHTTPClient allows you to a provide a custom http.Client.
func (r *Client) WithHTTPClient(client *http.Client) *Client {
r.xmlrpcClient = xmlrpc.NewClientWithHTTPClient(r.addr, client)
return r
}

// FieldValue contains the Field and Value of an attribute on a rTorrent
type FieldValue struct {
Field Field
Expand Down
6 changes: 3 additions & 3 deletions rtorrent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package rtorrent

import (
"context"
"io/ioutil"
"os"
"testing"
"time"

Expand Down Expand Up @@ -488,7 +488,7 @@ func TestRTorrent(t *testing.T) {
})

t.Run("with data", func(t *testing.T) {
b, err := ioutil.ReadFile("testdata/Fedora-i3-Live-x86_64-35.torrent")
b, err := os.ReadFile("testdata/Fedora-i3-Live-x86_64-35.torrent")
require.NoError(t, err)
require.NotEmpty(t, b)

Expand Down Expand Up @@ -562,7 +562,7 @@ func TestRTorrent(t *testing.T) {
})

t.Run("with data (stopped)", func(t *testing.T) {
b, err := ioutil.ReadFile("testdata/Fedora-i3-Live-x86_64-35.torrent")
b, err := os.ReadFile("testdata/Fedora-i3-Live-x86_64-35.torrent")
require.NoError(t, err)
require.NotEmpty(t, b)

Expand Down