From 08f64b3909e13f3a7e8137f238276bfa1ce84406 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 30 May 2017 00:07:05 +0200 Subject: [PATCH] Switched to net/http --- .gitignore | 5 ++++- rewrite.go | 22 ++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index fbec061f..09b2b8de 100644 --- a/.gitignore +++ b/.gitignore @@ -41,4 +41,7 @@ debug /notify.moe # DB -/db \ No newline at end of file +/db + +# Cert +/security \ No newline at end of file diff --git a/rewrite.go b/rewrite.go index 0e9d018c..a171a56b 100644 --- a/rewrite.go +++ b/rewrite.go @@ -1,29 +1,27 @@ package main import ( - "bytes" + "strings" "github.com/aerogo/aero" ) func init() { - plusRoute := []byte("/+") - plusRouteAjax := []byte("/_/+") + plusRoute := "/+" + plusRouteAjax := "/_/+" // This will rewrite /+UserName requests to /user/UserName app.Rewrite(func(ctx *aero.RewriteContext) { - requestURI := ctx.URIBytes() + requestURI := ctx.URI() - if bytes.HasPrefix(requestURI, plusRoute) { - newURI := []byte("/user/") + if strings.HasPrefix(requestURI, plusRoute) { + newURI := "/user/" userName := requestURI[2:] - newURI = append(newURI, userName...) - ctx.SetURIBytes(newURI) - } else if bytes.HasPrefix(requestURI, plusRouteAjax) { - newURI := []byte("/_/user/") + ctx.SetURI(newURI + userName) + } else if strings.HasPrefix(requestURI, plusRouteAjax) { + newURI := "/_/user/" userName := requestURI[4:] - newURI = append(newURI, userName...) - ctx.SetURIBytes(newURI) + ctx.SetURI(newURI + userName) } }) }