File: index.md

package info (click to toggle)
golang-github-nicholas-fedor-shoutrrr 0.8.17-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,332 kB
  • sloc: sh: 61; makefile: 5
file content (120 lines) | stat: -rw-r--r-- 3,603 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Proxy Setup

## Overview

Shoutrrr supports proxying HTTP requests for notification services, allowing you to route traffic through a proxy server. This can be configured using an environment variable or by customizing the HTTP client in code.

## Usage

### Environment Variable

Set the `HTTP_PROXY` environment variable to the proxy URL. This applies to all HTTP-based services used by Shoutrrr.

```bash title="Set HTTP_PROXY Environment Variable"
export HTTP_PROXY="socks5://localhost:1337"
```

### Custom HTTP Client

Override the default HTTP client in your Go code to configure a proxy with specific transport settings.

```go title="Configure Custom HTTP Client with Proxy"
import (
    "log"
    "net/http"
    "net/url"
    "time"
)

proxyURL, err := url.Parse("socks5://localhost:1337")
if err != nil {
    log.Fatalf("Error parsing proxy URL: %v", err)
}

http.DefaultClient.Transport = &http.Transport{
    Proxy: http.ProxyURL(proxyURL),
    DialContext: (&net.Dialer{
        Timeout:   30 * time.Second,
        KeepAlive: 30 * time.Second,
    }).DialContext,
    ForceAttemptHTTP2:     true,
    MaxIdleConns:          100,
    IdleConnTimeout:       90 * time.Second,
    TLSHandshakeTimeout:   10 * time.Second,
    ExpectContinueTimeout: 1 * time.Second,
}
```

## Examples

<!-- markdownlint-disable -->
### Using Environment Variable for Proxy

!!! Example
    ```bash title="Set Proxy and Send Notification"
    export HTTP_PROXY="socks5://localhost:1337"
    shoutrrr send --url "discord://abc123@123456789" --message "Hello via proxy!"
    ```

    ```text title="Expected Output"
    Notification sent
    ```

### Using Custom HTTP Client in Go

!!! Example
    ```go title="Send Notification with Proxy"
    package main

    import (
        "log"
        "net/http"
        "net/url"
        "time"
        "github.com/nicholas-fedor/shoutrrr"
    )

    func main() {
        proxyURL, err := url.Parse("socks5://localhost:1337")
        if err != nil {
            log.Fatalf("Error parsing proxy URL: %v", err)
        }

        http.DefaultClient.Transport = &http.Transport{
            Proxy: http.ProxyURL(proxyURL),
            DialContext: (&net.Dialer{
                Timeout:   30 * time.Second,
                KeepAlive: 30 * time.Second,
            }).DialContext,
            ForceAttemptHTTP2:     true,
            MaxIdleConns:          100,
            IdleConnTimeout:       90 * time.Second,
            TLSHandshakeTimeout:   10 * time.Second,
            ExpectContinueTimeout: 1 * time.Second,
        }

        url := "discord://abc123@123456789"
        errs := shoutrrr.Send(url, "Hello via proxy!")
        if len(errs) > 0 {
            for _, err := range errs {
                log.Println("Error:", err)
            }
        }
    }
    ```

    ```text title="Expected Output (Success)"
    (No output on success)
    ```

    ```text title="Expected Output (Error)"
    Error: failed to send message: unexpected response status code
    ```
<!-- markdownlint-restore -->

## Notes

- **Environment Variable**: `HTTP_PROXY` supports protocols like `http`, `https`, or `socks5`. It affects all HTTP-based services globally.
- **Custom HTTP Client**: Provides fine-grained control over proxy settings, suitable for Go applications requiring specific transport configurations.
- **Service Compatibility**: Ensure the proxy supports the protocol used by the service (e.g., HTTPS for Discord, SMTP).
- **Timeouts**: The custom client example includes a 30-second dial timeout and 10-second TLS handshake timeout, adjustable as needed.