aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Mills <prologic@shortcircuit.net.au>2016-09-22 11:22:10 +1000
committerJames Mills <prologic@shortcircuit.net.au>2016-09-22 11:22:10 +1000
commit773606bd45e283d05a4aaa06787289ad322ca7b7 (patch)
treef82287ca30e93aa5b30c8cc258e01b0ce851891a
downloadgopherproxy-773606bd45e283d05a4aaa06787289ad322ca7b7.tar.gz
gopherproxy-773606bd45e283d05a4aaa06787289ad322ca7b7.tar.bz2
gopherproxy-773606bd45e283d05a4aaa06787289ad322ca7b7.zip
Initial Commit
-rw-r--r--.gitignore3
-rw-r--r--.travis.yml1
-rw-r--r--Dockerfile5
-rw-r--r--LICENSE22
-rw-r--r--README.md30
-rw-r--r--main.go47
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
3gopherproxy
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 @@
1FROM golang:alpine
2
3EXPOSE 80/tcp
4
5ENTRYPOINT ["/gopherproxy"]
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..72873e6
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
1Copyright (C) 2016 James Mills
2
3go-gopher is covered by the MIT license::
4
5Permission is hereby granted, free of charge, to any person
6obtaining a copy of this software and associated documentation
7files (the "Software"), to deal in the Software without restriction,
8including without limitation the rights to use, copy, modify, merge,
9publish, distribute, sublicense, and/or sell copies of the Software,
10and to permit persons to whom the Software is furnished to do so,
11subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included
14in all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22OR 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[![Build Status](https://travis-ci.org/prologic/gopherproxy.svg)](https://travis-ci.org/prologic/gopherproxy)
4
5This is a Gopher (RFC 1436) Web Proxy that acts as a gateway into Gopherspace
6by proxying standard Web HTTP requests to Gopher requests of the target server.
7
8gopherproxy 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
21By default gopherproxy will proxy requests to a locally running Gopher server
22on gopher://localhost:70/ -- To change where to proxy to:
23
24```#!bash
25$ gopherproxy -host gopher.floodgap.com
26```
27
28## License
29
30MIT
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..be625c6
--- /dev/null
+++ b/main.go
@@ -0,0 +1,47 @@
1package main
2
3import (
4 "flag"
5 "fmt"
6 "io"
7 "log"
8 "net/http"
9 "strings"
10
11 "github.com/prologic/go-gopher"
12)
13
14var (
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
20func 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
42func main() {
43 flag.Parse()
44
45 http.HandleFunc("/", proxy)
46 log.Fatal(http.ListenAndServe(*bind, nil))
47}