Skip to content

Commit

Permalink
Clean up outline-fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna committed Oct 14, 2023
1 parent b0f7b4f commit 11b8cea
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This app illustrates how to use different transports to fetch a URL in Go.
Direct fetch:

```sh
$ go run github.com/Jigsaw-Code/outline-sdk/x/examples/outline-fetch@latest https://ipinfo.io
$ go run github.com/Jigsaw-Code/outline-sdk/x/examples/fetch@latest https://ipinfo.io
{
...
"city": "Amsterdam",
Expand All @@ -18,7 +18,7 @@ $ go run github.com/Jigsaw-Code/outline-sdk/x/examples/outline-fetch@latest http
Using a Shadowsocks server:

```sh
$ go run github.com/Jigsaw-Code/outline-sdk/x/examples/outline-fetch@latest -transport ss://[redacted]@[redacted]:80 https://ipinfo.io
$ go run github.com/Jigsaw-Code/outline-sdk/x/examples/fetch@latest -transport ss://[redacted]@[redacted]:80 https://ipinfo.io
{
...
"region": "New Jersey",
Expand All @@ -31,7 +31,7 @@ $ go run github.com/Jigsaw-Code/outline-sdk/x/examples/outline-fetch@latest -tra
Using a SOCKS5 server:

```sh
$ go run github.com/Jigsaw-Code/outline-sdk/x/examples/outline-fetch@latest -transport socks5://[redacted]:5703 https://ipinfo.io
$ go run github.com/Jigsaw-Code/outline-sdk/x/examples/fetch@latest -transport socks5://[redacted]:5703 https://ipinfo.io
{
...
"city": "Berlin",
Expand All @@ -44,7 +44,7 @@ $ go run github.com/Jigsaw-Code/outline-sdk/x/examples/outline-fetch@latest -tra
Using packet splitting:

```sh
$ go run github.com/Jigsaw-Code/outline-sdk/x/examples/outline-fetch@latest -transport split:3 https://ipinfo.io
$ go run github.com/Jigsaw-Code/outline-sdk/x/examples/fetch@latest -transport split:3 https://ipinfo.io
{
...
"city": "Amsterdam",
Expand Down
26 changes: 25 additions & 1 deletion x/examples/outline-fetch/main.go → x/examples/fetch/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,36 @@ import (
"net"
"net/http"
"os"
"path"
"strings"

"github.com/Jigsaw-Code/outline-sdk/x/config"
)

var debugLog log.Logger = *log.New(io.Discard, "", 0)

func init() {
flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [flags...] <url>\n", path.Base(os.Args[0]))
flag.PrintDefaults()
}
}

func main() {
verboseFlag := flag.Bool("v", false, "Enable debug output")
transportFlag := flag.String("transport", "", "Transport config")

flag.Parse()

if *verboseFlag {
debugLog = *log.New(os.Stderr, "[DEBUG] ", log.LstdFlags|log.Lmicroseconds|log.Lshortfile)
}

url := flag.Arg(0)
if url == "" {
log.Fatal("Need to pass the URL to fetch in the command-line")
log.Print("Need to pass the URL to fetch in the command-line")
flag.Usage()
os.Exit(1)
}

dialer, err := config.NewStreamDialer(*transportFlag)
Expand All @@ -55,6 +73,12 @@ func main() {
}
defer resp.Body.Close()

if *verboseFlag {
for k, v := range resp.Header {
debugLog.Printf("%v: %v", k, v)
}
}

_, err = io.Copy(os.Stdout, resp.Body)
if err != nil {
log.Fatalf("Read of page body failed: %v", err)
Expand Down

0 comments on commit 11b8cea

Please sign in to comment.