diff --git a/morty.go b/morty.go
index 85ccac5..8a85cce 100644
--- a/morty.go
+++ b/morty.go
@@ -219,6 +219,39 @@ var HTML_HEAD_CONTENT_TYPE string = `
`
+var MORTY_HTML_PAGE_START string = `
+
+
+MortyProxy
+
+
+
+
+
+
MortyProxy
+`
+
+var MORTY_HTML_PAGE_END string = `
+
+
+
+`
+
var FAVICON_BYTES []byte
func init() {
@@ -252,18 +285,18 @@ func (p *Proxy) RequestHandler(ctx *fasthttp.RequestCtx) {
parsedURI, err := url.Parse(string(requestURI))
- if strings.HasSuffix(parsedURI.Host, ".onion") {
- // HTTP status code 501 : Not Implemented
- p.serveMainPage(ctx, 501, errors.New("Tor urls are not supported yet"))
- return
- }
-
if err != nil {
// HTTP status code 500 : Internal Server Error
p.serveMainPage(ctx, 500, err)
return
}
+ // Serve an intermediate page for protocols other than HTTP(S)
+ if (parsedURI.Scheme != "http" && parsedURI.Scheme != "https") || strings.HasSuffix(parsedURI.Host, ".onion") {
+ p.serveExitMortyPage(ctx, parsedURI)
+ return
+ }
+
req := fasthttp.AcquireRequest()
defer fasthttp.ReleaseRequest(req)
req.SetConnectionClose()
@@ -893,31 +926,23 @@ func verifyRequestURI(uri, hashMsg, key []byte) bool {
return hmac.Equal(h, mac.Sum(nil))
}
+func (p *Proxy) serveExitMortyPage(ctx *fasthttp.RequestCtx, uri *url.URL) {
+ ctx.SetContentType("text/html")
+ ctx.SetStatusCode(403)
+ ctx.Write([]byte(MORTY_HTML_PAGE_START))
+ ctx.Write([]byte("You are about to exit MortyProxy
"))
+ ctx.Write([]byte("Following
"))
+ ctx.Write([]byte(html.EscapeString(uri.String())))
+ ctx.Write([]byte("
the content of this URL will be NOT sanitized.
"))
+ ctx.Write([]byte(MORTY_HTML_PAGE_END))
+}
+
func (p *Proxy) serveMainPage(ctx *fasthttp.RequestCtx, statusCode int, err error) {
ctx.SetContentType("text/html; charset=UTF-8")
ctx.SetStatusCode(statusCode)
- ctx.Write([]byte(`
-
-
-MortyProxy
-
-
-
-
-
-
MortyProxy
-`))
+ ctx.Write([]byte(MORTY_HTML_PAGE_START))
if err != nil {
log.Println("error:", err)
ctx.Write([]byte("Error: "))
@@ -933,15 +958,7 @@ h1 { font-size: 3em; }
} else {
ctx.Write([]byte(`Warning! This instance does not support direct URL opening.
`))
}
- ctx.Write([]byte(`
-
-
-
-`))
+ ctx.Write([]byte(MORTY_HTML_PAGE_END))
}
func main() {