diff options
| author | James Mills <prologic@shortcircuit.net.au> | 2016-09-22 11:22:10 +1000 | 
|---|---|---|
| committer | James Mills <prologic@shortcircuit.net.au> | 2016-09-22 11:22:10 +1000 | 
| commit | 773606bd45e283d05a4aaa06787289ad322ca7b7 (patch) | |
| tree | f82287ca30e93aa5b30c8cc258e01b0ce851891a | |
| download | gopherproxy-773606bd45e283d05a4aaa06787289ad322ca7b7.tar.gz gopherproxy-773606bd45e283d05a4aaa06787289ad322ca7b7.tar.bz2 gopherproxy-773606bd45e283d05a4aaa06787289ad322ca7b7.zip | |
Initial Commit
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | .travis.yml | 1 | ||||
| -rw-r--r-- | Dockerfile | 5 | ||||
| -rw-r--r-- | LICENSE | 22 | ||||
| -rw-r--r-- | README.md | 30 | ||||
| -rw-r--r-- | main.go | 47 | 
6 files changed, 108 insertions, 0 deletions
| diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fcbcc28 --- /dev/null +++ b/.gitignore | |||
| @@ -0,0 +1,3 @@ | |||
| 1 | *~ | ||
| 2 | *.bak | ||
| 3 | gopherproxy | ||
| diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..4f2ee4d --- /dev/null +++ b/.travis.yml | |||
| @@ -0,0 +1 @@ | |||
| language: go | |||
| diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1dad4b6 --- /dev/null +++ b/Dockerfile | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | FROM golang:alpine | ||
| 2 | |||
| 3 | EXPOSE 80/tcp | ||
| 4 | |||
| 5 | ENTRYPOINT ["/gopherproxy"] | ||
| @@ -0,0 +1,22 @@ | |||
| 1 | Copyright (C) 2016 James Mills | ||
| 2 | |||
| 3 | go-gopher is covered by the MIT license:: | ||
| 4 | |||
| 5 | Permission is hereby granted, free of charge, to any person | ||
| 6 | obtaining a copy of this software and associated documentation | ||
| 7 | files (the "Software"), to deal in the Software without restriction, | ||
| 8 | including without limitation the rights to use, copy, modify, merge, | ||
| 9 | publish, distribute, sublicense, and/or sell copies of the Software, | ||
| 10 | and to permit persons to whom the Software is furnished to do so, | ||
| 11 | subject to the following conditions: | ||
| 12 | |||
| 13 | The above copyright notice and this permission notice shall be included | ||
| 14 | in all copies or substantial portions of the Software. | ||
| 15 | |||
| 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
| 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
| 20 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
| 21 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE | ||
| 22 | OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| diff --git a/README.md b/README.md new file mode 100644 index 0000000..9e4831a --- /dev/null +++ b/README.md | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | # Gopher (RFC 1436) Web Proxy | ||
| 2 | |||
| 3 | [](https://travis-ci.org/prologic/gopherproxy) | ||
| 4 | |||
| 5 | This is a Gopher (RFC 1436) Web Proxy that acts as a gateway into Gopherspace | ||
| 6 | by proxying standard Web HTTP requests to Gopher requests of the target server. | ||
| 7 | |||
| 8 | gopherproxy is written in Go (#golang) using the | ||
| 9 | [go-gopher](https://github.com/prologic/go-gopher) library. | ||
| 10 | |||
| 11 | ## Installation | ||
| 12 | |||
| 13 | $ go install github.com/prologic/gopherproxy | ||
| 14 | |||
| 15 | ## Usage | ||
| 16 | |||
| 17 | ```#!bash | ||
| 18 | $ gopherproxy | ||
| 19 | ``` | ||
| 20 | |||
| 21 | By default gopherproxy will proxy requests to a locally running Gopher server | ||
| 22 | on gopher://localhost:70/ -- To change where to proxy to: | ||
| 23 | |||
| 24 | ```#!bash | ||
| 25 | $ gopherproxy -host gopher.floodgap.com | ||
| 26 | ``` | ||
| 27 | |||
| 28 | ## License | ||
| 29 | |||
| 30 | MIT | ||
| @@ -0,0 +1,47 @@ | |||
| 1 | package main | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "flag" | ||
| 5 | "fmt" | ||
| 6 | "io" | ||
| 7 | "log" | ||
| 8 | "net/http" | ||
| 9 | "strings" | ||
| 10 | |||
| 11 | "github.com/prologic/go-gopher" | ||
| 12 | ) | ||
| 13 | |||
| 14 | var ( | ||
| 15 | bind = flag.String("bind", ":80", "[int]:port to bind to") | ||
| 16 | host = flag.String("host", "localhost", "host to proxy to") | ||
| 17 | port = flag.Int("port", 70, "port to proxy to") | ||
| 18 | ) | ||
| 19 | |||
| 20 | func proxy(res http.ResponseWriter, req *http.Request) { | ||
| 21 | path := strings.TrimPrefix(req.URL.Path, "/") | ||
| 22 | |||
| 23 | gr, err := gopher.Get(fmt.Sprintf("gopher://%s:%d/%s", *host, *port, path)) | ||
| 24 | if err != nil { | ||
| 25 | io.WriteString(res, fmt.Sprintf("<b>Error:</b><pre>%s</pre>", err)) | ||
| 26 | return | ||
| 27 | } | ||
| 28 | |||
| 29 | if gr.Body != nil { | ||
| 30 | io.Copy(res, gr.Body) | ||
| 31 | } else { | ||
| 32 | bytes, err := gr.Dir.ToText() | ||
| 33 | if err != nil { | ||
| 34 | io.WriteString(res, fmt.Sprintf("<b>Error:</b><pre>%s</pre>", err)) | ||
| 35 | return | ||
| 36 | } | ||
| 37 | |||
| 38 | io.WriteString(res, string(bytes)) | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | func main() { | ||
| 43 | flag.Parse() | ||
| 44 | |||
| 45 | http.HandleFunc("/", proxy) | ||
| 46 | log.Fatal(http.ListenAndServe(*bind, nil)) | ||
| 47 | } | ||
