1
0
mirror of https://github.com/kataras/iris.git synced 2026-02-07 19:25:58 +00:00

Add test for Redirect while ListenTLS/ListenLETSENCRYPT

This commit is contained in:
Gerasimos (Makis) Maropoulos
2016-12-04 06:53:08 +02:00
parent b62302d1d7
commit 0513fa745b
3 changed files with 84 additions and 23 deletions

View File

@@ -471,6 +471,10 @@ func (ctx *Context) SetHeader(k string, v string) {
ctx.RequestCtx.Response.Header.Set(k, v)
}
// it used only inside Redirect,
// keep it here for allocations reason
var httpsSchemeOnlyBytes = []byte("https")
// Redirect redirect sends a redirect response the client
// accepts 2 parameters string and an optional int
// first parameter is the url to redirect
@@ -486,12 +490,10 @@ func (ctx *Context) Redirect(urlToRedirect string, statusHeader ...int) {
// #355
if ctx.IsTLS() {
u := fasthttp.AcquireURI()
ctx.URI().CopyTo(u)
u.SetScheme("https")
u := ctx.URI()
u.SetSchemeBytes(httpsSchemeOnlyBytes)
u.Update(urlToRedirect)
ctx.SetHeader("Location", string(u.FullURI()))
fasthttp.ReleaseURI(u)
ctx.SetStatusCode(httpStatus)
return
}