Use temporary redirects

This commit is contained in:
Eduard Urbach 2019-06-03 15:06:57 +09:00
parent e11295019b
commit cf258573a8
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
12 changed files with 28 additions and 23 deletions

View File

@ -32,6 +32,6 @@ func Install(app *aero.Application) {
ctx.Session().Delete("userId")
}
return ctx.Redirect(http.StatusFound, "/")
return ctx.Redirect(http.StatusTemporaryRedirect, "/")
})
}

View File

@ -48,7 +48,7 @@ func InstallFacebookAuth(app *aero.Application) {
app.Get("/auth/facebook", func(ctx aero.Context) error {
state := ctx.Session().ID()
url := config.AuthCodeURL(state)
return ctx.Redirect(http.StatusFound, url)
return ctx.Redirect(http.StatusTemporaryRedirect, url)
})
// This is the redirect URL that we specified in the OAuth2 config.
@ -111,7 +111,7 @@ func InstallFacebookAuth(app *aero.Application) {
// Log
authLog.Info("Added Facebook ID to existing account | %s | %s | %s | %s | %s", user.Nick, user.ID, ctx.IP(), user.Email, user.RealName())
return ctx.Redirect(http.StatusFound, "/")
return ctx.Redirect(http.StatusTemporaryRedirect, "/")
}
var getErr error
@ -129,7 +129,7 @@ func InstallFacebookAuth(app *aero.Application) {
user.Save()
session.Set("userId", user.ID)
return ctx.Redirect(http.StatusFound, "/")
return ctx.Redirect(http.StatusTemporaryRedirect, "/")
}
// Try to find an existing user via the associated e-mail address
@ -142,7 +142,7 @@ func InstallFacebookAuth(app *aero.Application) {
user.Save()
session.Set("userId", user.ID)
return ctx.Redirect(http.StatusFound, "/")
return ctx.Redirect(http.StatusTemporaryRedirect, "/")
}
// Register new user
@ -173,6 +173,6 @@ func InstallFacebookAuth(app *aero.Application) {
authLog.Info("Registered new user via Facebook | %s | %s | %s | %s | %s", user.Nick, user.ID, ctx.IP(), user.Email, user.RealName())
// Redirect to starting page for new users
return ctx.Redirect(http.StatusFound, newUserStartRoute)
return ctx.Redirect(http.StatusTemporaryRedirect, newUserStartRoute)
})
}

View File

@ -55,7 +55,7 @@ func InstallGoogleAuth(app *aero.Application) {
app.Get("/auth/google", func(ctx aero.Context) error {
state := ctx.Session().ID()
url := config.AuthCodeURL(state)
return ctx.Redirect(http.StatusFound, url)
return ctx.Redirect(http.StatusTemporaryRedirect, url)
})
// This is the redirect URL that we specified in the OAuth2 config.
@ -122,7 +122,7 @@ func InstallGoogleAuth(app *aero.Application) {
// Log
authLog.Info("Added Google ID to existing account | %s | %s | %s | %s | %s", user.Nick, user.ID, ctx.IP(), user.Email, user.RealName())
return ctx.Redirect(http.StatusFound, "/")
return ctx.Redirect(http.StatusTemporaryRedirect, "/")
}
var getErr error
@ -137,7 +137,7 @@ func InstallGoogleAuth(app *aero.Application) {
user.Save()
session.Set("userId", user.ID)
return ctx.Redirect(http.StatusFound, "/")
return ctx.Redirect(http.StatusTemporaryRedirect, "/")
}
// Try to find an existing user via the associated e-mail address
@ -153,7 +153,7 @@ func InstallGoogleAuth(app *aero.Application) {
user.Save()
session.Set("userId", user.ID)
return ctx.Redirect(http.StatusFound, "/")
return ctx.Redirect(http.StatusTemporaryRedirect, "/")
}
// Register new user
@ -184,6 +184,6 @@ func InstallGoogleAuth(app *aero.Application) {
authLog.Info("Registered new user via Google | %s | %s | %s | %s | %s", user.Nick, user.ID, ctx.IP(), user.Email, user.RealName())
// Redirect to starting page for new users
return ctx.Redirect(http.StatusFound, newUserStartRoute)
return ctx.Redirect(http.StatusTemporaryRedirect, newUserStartRoute)
})
}

View File

@ -53,7 +53,7 @@ func InstallTwitterAuth(app *aero.Application) {
ctx.Session().Set("tempCred", tempCred)
url := config.AuthorizationURL(tempCred, nil)
return ctx.Redirect(http.StatusFound, url)
return ctx.Redirect(http.StatusTemporaryRedirect, url)
})
// This is the redirect URL that we specified in /auth/twitter.
@ -124,7 +124,7 @@ func InstallTwitterAuth(app *aero.Application) {
// Log
authLog.Info("Added Twitter ID to existing account | %s | %s | %s | %s | %s", user.Nick, user.ID, ctx.IP(), user.Email, user.RealName())
return ctx.Redirect(http.StatusFound, "/")
return ctx.Redirect(http.StatusTemporaryRedirect, "/")
}
var getErr error
@ -139,7 +139,7 @@ func InstallTwitterAuth(app *aero.Application) {
user.Save()
session.Set("userId", user.ID)
return ctx.Redirect(http.StatusFound, "/")
return ctx.Redirect(http.StatusTemporaryRedirect, "/")
}
// Try to find an existing user via the associated e-mail address
@ -156,7 +156,7 @@ func InstallTwitterAuth(app *aero.Application) {
user.Save()
session.Set("userId", user.ID)
return ctx.Redirect(http.StatusFound, "/")
return ctx.Redirect(http.StatusTemporaryRedirect, "/")
}
// Register new user
@ -191,6 +191,6 @@ func InstallTwitterAuth(app *aero.Application) {
authLog.Info("Registered new user via Twitter | %s | %s | %s | %s | %s", user.Nick, user.ID, ctx.IP(), user.Email, user.RealName())
// Redirect to starting page for new users
return ctx.Redirect(http.StatusFound, newUserStartRoute)
return ctx.Redirect(http.StatusTemporaryRedirect, newUserStartRoute)
})
}

5
go.sum
View File

@ -9,6 +9,9 @@ github.com/PuerkitoBio/goquery v1.5.0 h1:uGvmFXOA73IKluu/F84Xd1tt/z07GYm8X49XKHP
github.com/PuerkitoBio/goquery v1.5.0/go.mod h1:qD2PgZ9lccMbQlc7eEOjaeRlFQON7xY8kdmcsrnKqMg=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d h1:G0m3OIz70MZUWq3EgK3CesDbo8upS2Vm9/P3FtgI+Jk=
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/aerogo/aero v1.3.1/go.mod h1:5rPhXo2DNMFQ7XhDsuZ3L7Zr6TH/349+WczUbrOUZvM=
github.com/aerogo/aero v1.3.10 h1:KTAscWcducqxa6LcqXe1lJA04E5FPQ6l8MCG3VCNtP4=
github.com/aerogo/aero v1.3.10/go.mod h1:DZA+Yt0AevLyvNG7w1CyYoZZfoFMysABOOrFrgrQhHM=
github.com/aerogo/api v0.2.0 h1:mIc/y381e+Qc85eSc2cKPdpDDOmT0hlnEeCw2Dcf7no=
github.com/aerogo/api v0.2.0/go.mod h1:6objJn5XiKpYpywQUPrFjxZIXD4NVI2LwcBNYCEcS3Y=
github.com/aerogo/cluster v0.1.6 h1:9HYjJwo19uuh9thIc80T3caap9t9b4BXZ1iN8aztjlU=
@ -67,6 +70,7 @@ github.com/akyoto/color v1.8.5 h1:xvHRmBJdsT5HJxnfyIT8l3zNbexA/2YIIeAlaHuhYGY=
github.com/akyoto/color v1.8.5/go.mod h1:mI8lhoKcgnvH8fnaupVUE3BmKUp2bpDn5wFS1xEQ4hw=
github.com/akyoto/go-matroska v0.1.1 h1:HgoCAkeWrGjYr0FZr3yCzAIkXuOGRiVil7Ul329lm+A=
github.com/akyoto/go-matroska v0.1.1/go.mod h1:x+GUVwyby6HN/MKKNP4BvGqP9VrHuEznfBf288gehek=
github.com/akyoto/hash v0.3.5/go.mod h1:uPmnZyhBJIyLON8V9LNi0CcqtwYaH2RiKLFQg67fwq0=
github.com/akyoto/hash v0.4.0 h1:M9Q3E6cOAxbf7q3yu5SZZdbZxC4thndCkqJctxl1+zg=
github.com/akyoto/hash v0.4.0/go.mod h1:purxg2OohOWT7H0oLP0xQF1DG/EbazUbw7zomRUk8Y8=
github.com/akyoto/imageserver v0.3.6 h1:Sxcbgo45Lh7afcSmcU8OS49VYbqh4kE3DK0Lxuuxf74=
@ -274,6 +278,7 @@ golang.org/x/sys v0.0.0-20190516014833-cab07311ab81 h1:5Q88vZAfC0WB8T1GHRLttQaZd
golang.org/x/sys v0.0.0-20190516014833-cab07311ab81/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190523142557-0e01d883c5c5 h1:sM3evRHxE/1RuMe1FYAL3j7C7fUfIjkbE+NiDAYUF8U=
golang.org/x/sys v0.0.0-20190523142557-0e01d883c5c5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed h1:uPxWBzB3+mlnjy9W58qY1j/cjyFjutgw/Vhan2zLy/A=
golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=

View File

@ -9,7 +9,7 @@ package middleware
// if !strings.HasPrefix(request.Protocol(), "HTTP/2") && isBrowser {
// fmt.Println("Redirect to HTTPS")
// ctx.Redirect(http.StatusFound, "https://" + request.Host() + request.URL().Path)
// ctx.Redirect(http.StatusTemporaryRedirect, "https://" + request.Host() + request.URL().Path)
// ctx.Response().WriteHeader(ctx.Status())
// return
// }

View File

@ -75,7 +75,7 @@ func logRequest(ctx aero.Context, responseTime time.Duration) {
// Log all requests that failed
switch ctx.Status() {
case http.StatusOK, http.StatusFound, http.StatusMovedPermanently, http.StatusPermanentRedirect, http.StatusTemporaryRedirect:
case http.StatusOK, http.StatusTemporaryRedirect, http.StatusPermanentRedirect:
// Ok.
default:

View File

@ -19,7 +19,7 @@ func Get(ctx aero.Context) error {
user := utils.GetUser(ctx)
if user == nil || (user.Role != "admin" && user.Role != "editor") {
return ctx.Redirect(http.StatusFound, "/")
return ctx.Redirect(http.StatusTemporaryRedirect, "/")
}
// // CPU

View File

@ -15,5 +15,5 @@ func Redirect(ctx aero.Context) error {
return ctx.Error(http.StatusUnauthorized, "Not logged in")
}
return ctx.Redirect(http.StatusFound, "/+" + user.Nick + ctx.Path())
return ctx.Redirect(http.StatusTemporaryRedirect, "/+" + user.Nick + ctx.Path())
}

View File

@ -15,7 +15,7 @@ func Get(ctx aero.Context) error {
user := utils.GetUser(ctx)
if user == nil || (user.Role != "admin" && user.Role != "editor") {
return ctx.Redirect(http.StatusFound, "/")
return ctx.Redirect(http.StatusTemporaryRedirect, "/")
}
ignoreDifferences := arn.FilterIgnoreAnimeDifferences(func(entry *arn.IgnoreAnimeDifference) bool {

View File

@ -16,7 +16,7 @@ func NoDescription(ctx aero.Context) error {
user := utils.GetUser(ctx)
if user == nil || (user.Role != "admin" && user.Role != "editor") {
return ctx.Redirect(http.StatusFound, "/")
return ctx.Redirect(http.StatusTemporaryRedirect, "/")
}
companies := arn.FilterCompanies(func(company *arn.Company) bool {

View File

@ -16,5 +16,5 @@ func SmartRedirect(ctx aero.Context, uri string) error {
prefix = "/_"
}
return ctx.Redirect(http.StatusFound, prefix+uri)
return ctx.Redirect(http.StatusTemporaryRedirect, prefix+uri)
}