Initial Commit

This commit is contained in:
James Mills 2016-09-22 11:22:10 +10:00
commit 773606bd45
No known key found for this signature in database
GPG Key ID: AC4C014F1440EBD6
6 changed files with 108 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*~
*.bak
gopherproxy

1
.travis.yml Normal file
View File

@ -0,0 +1 @@
language: go

5
Dockerfile Normal file
View File

@ -0,0 +1,5 @@
FROM golang:alpine
EXPOSE 80/tcp
ENTRYPOINT ["/gopherproxy"]

22
LICENSE Normal file
View File

@ -0,0 +1,22 @@
Copyright (C) 2016 James Mills
go-gopher is covered by the MIT license::
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

30
README.md Normal file
View File

@ -0,0 +1,30 @@
# Gopher (RFC 1436) Web Proxy
[![Build Status](https://travis-ci.org/prologic/gopherproxy.svg)](https://travis-ci.org/prologic/gopherproxy)
This is a Gopher (RFC 1436) Web Proxy that acts as a gateway into Gopherspace
by proxying standard Web HTTP requests to Gopher requests of the target server.
gopherproxy is written in Go (#golang) using the
[go-gopher](https://github.com/prologic/go-gopher) library.
## Installation
$ go install github.com/prologic/gopherproxy
## Usage
```#!bash
$ gopherproxy
```
By default gopherproxy will proxy requests to a locally running Gopher server
on gopher://localhost:70/ -- To change where to proxy to:
```#!bash
$ gopherproxy -host gopher.floodgap.com
```
## License
MIT

47
main.go Normal file
View File

@ -0,0 +1,47 @@
package main
import (
"flag"
"fmt"
"io"
"log"
"net/http"
"strings"
"github.com/prologic/go-gopher"
)
var (
bind = flag.String("bind", ":80", "[int]:port to bind to")
host = flag.String("host", "localhost", "host to proxy to")
port = flag.Int("port", 70, "port to proxy to")
)
func proxy(res http.ResponseWriter, req *http.Request) {
path := strings.TrimPrefix(req.URL.Path, "/")
gr, err := gopher.Get(fmt.Sprintf("gopher://%s:%d/%s", *host, *port, path))
if err != nil {
io.WriteString(res, fmt.Sprintf("<b>Error:</b><pre>%s</pre>", err))
return
}
if gr.Body != nil {
io.Copy(res, gr.Body)
} else {
bytes, err := gr.Dir.ToText()
if err != nil {
io.WriteString(res, fmt.Sprintf("<b>Error:</b><pre>%s</pre>", err))
return
}
io.WriteString(res, string(bytes))
}
}
func main() {
flag.Parse()
http.HandleFunc("/", proxy)
log.Fatal(http.ListenAndServe(*bind, nil))
}