Skip to content

Commit

Permalink
Merge branch 'release/0.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
nwtgck committed Oct 18, 2020
2 parents f5fb916 + 06cd2cc commit 43d9c28
Show file tree
Hide file tree
Showing 9 changed files with 254 additions and 15 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)

## [Unreleased]

## [0.2.1] - 2020-10-18
### Added
* Add --header flag to specify HTTP header

## [0.2.0] - 2020-10-12
### Changed
* Change server-host as "server" subcommand, not root command
Expand All @@ -18,5 +22,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
### Added
* Initial release

[Unreleased]: https://github.com/nwtgck/go-piping-tunnel/compare/v0.2.0...HEAD
[Unreleased]: https://github.com/nwtgck/go-piping-tunnel/compare/v0.2.1...HEAD
[0.2.1]: https://github.com/nwtgck/go-piping-tunnel/compare/v0.2.0...v0.2.1
[0.2.0]: https://github.com/nwtgck/go-piping-tunnel/compare/v0.1.0...v0.2.0
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ Available Commands:
server Run server-host
Flags:
--dns-server string DNS server (e.g. 1.1.1.1:53)
-h, --help help for piping-tunnel
-k, --insecure Allow insecure server connections when using SSL
--progress Show progress (default true)
-s, --server string Piping Server URL (default "https://ppng.io")
-v, --version show version
--dns-server string DNS server (e.g. 1.1.1.1:53)
-H, --header stringArray HTTP header
-h, --help help for piping-tunnel
-k, --insecure Allow insecure server connections when using SSL
--progress Show progress (default true)
-s, --server string Piping Server URL (default "https://ppng.io")
-v, --version show version
Use "piping-tunnel [command] --help" for more information about a command.
```
Expand Down
21 changes: 19 additions & 2 deletions cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"github.com/nwtgck/go-piping-tunnel/io_progress"
piping_tunnel_util "github.com/nwtgck/go-piping-tunnel/piping-tunnel-util"
"github.com/nwtgck/go-piping-tunnel/util"
"github.com/spf13/cobra"
"io"
Expand All @@ -28,6 +29,10 @@ var clientCmd = &cobra.Command{
if err != nil {
return err
}
headers, err := piping_tunnel_util.ParseKeyValueStrings(headerKeyValueStrs)
if err != nil {
return err
}
ln, err := net.Listen("tcp", fmt.Sprintf(":%d", clientHostPort))
if err != nil {
return err
Expand Down Expand Up @@ -86,14 +91,26 @@ var clientCmd = &cobra.Command{
if progress != nil {
reader = progress
}
_, err = httpClient.Post(clientToServerUrl, "application/octet-stream", reader)
req, err := http.NewRequest("POST", clientToServerUrl, reader)
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/octet-stream")
for _, kv := range headers {
req.Header.Set(kv.Key, kv.Value)
}
_, err = httpClient.Do(req)
if err != nil {
return err
}
res, err := httpClient.Get(serverToClientUrl)
req, err = http.NewRequest("GET", serverToClientUrl, nil)
if err != nil {
return err
}
for _, kv := range headers {
req.Header.Set(kv.Key, kv.Value)
}
res, err := httpClient.Do(req)
var writer io.Writer = conn
if progress != nil {
writer = io.MultiWriter(conn, progress)
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var insecure bool
var dnsServer string
var showsVersion bool
var showProgress bool
var headerKeyValueStrs []string

func init() {
cobra.OnInitialize()
Expand All @@ -28,6 +29,7 @@ func init() {
RootCmd.PersistentFlags().StringVar(&dnsServer, "dns-server", "", "DNS server (e.g. 1.1.1.1:53)")
// NOTE: --insecure, -k is inspired by curl
RootCmd.PersistentFlags().BoolVarP(&insecure, "insecure", "k", false, "Allow insecure server connections when using SSL")
RootCmd.PersistentFlags().StringArrayVarP(&headerKeyValueStrs, "header", "H", []string{}, "HTTP header")
RootCmd.PersistentFlags().BoolVarP(&showProgress, "progress", "", true, "Show progress")
RootCmd.Flags().BoolVarP(&showsVersion, "version", "v", false, "show version")
}
Expand Down
24 changes: 22 additions & 2 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"
"github.com/nwtgck/go-piping-tunnel/io_progress"
piping_tunnel_util "github.com/nwtgck/go-piping-tunnel/piping-tunnel-util"
"github.com/nwtgck/go-piping-tunnel/util"
"github.com/spf13/cobra"
"io"
Expand All @@ -28,6 +29,10 @@ var serverCmd = &cobra.Command{
if err != nil {
return err
}
headers, err := piping_tunnel_util.ParseKeyValueStrings(headerKeyValueStrs)
if err != nil {
return err
}
conn, err := net.Dial("tcp", fmt.Sprintf("localhost:%d", serverHostPort))
if err != nil {
return err
Expand Down Expand Up @@ -61,7 +66,15 @@ var serverCmd = &cobra.Command{
if progress != nil {
reader = progress
}
_, err = httpClient.Post(serverToClientUrl, "application/octet-stream", reader)
req, err := http.NewRequest("POST", serverToClientUrl, reader)
if err != nil {
return err
}
req.Header.Set("Content-Type", "application/octet-stream")
for _, kv := range headers {
req.Header.Set(kv.Key, kv.Value)
}
_, err = httpClient.Do(req)
if err != nil {
return err
}
Expand All @@ -84,7 +97,14 @@ var serverCmd = &cobra.Command{
serverToClientPath,
)

res, err := httpClient.Get(clientToServerUrl)
req, err = http.NewRequest("GET", clientToServerUrl, nil)
if err != nil {
return err
}
for _, kv := range headers {
req.Header.Set(kv.Key, kv.Value)
}
res, err := httpClient.Do(req)
if err != nil {
return err
}
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ module github.com/nwtgck/go-piping-tunnel

go 1.14

require (
github.com/spf13/cobra v1.0.0
)
require github.com/spf13/cobra v1.1.0
Loading

0 comments on commit 43d9c28

Please sign in to comment.