Update to 5.4.3, zero user changes.

This commit is contained in:
Gerasimos Maropoulos 2016-10-13 04:02:04 +03:00
parent 26fdbd948e
commit f2a7b4e43a
5 changed files with 38 additions and 136 deletions

View File

@ -19,7 +19,7 @@
<br/> <br/>
<a href="https://github.com/kataras/iris/releases"><img src="https://img.shields.io/badge/%20version%20-%204.5.2%20-blue.svg?style=flat-square" alt="Releases"></a> <a href="https://github.com/kataras/iris/releases"><img src="https://img.shields.io/badge/%20version%20-%204.5.3%20-blue.svg?style=flat-square" alt="Releases"></a>
<a href="https://github.com/iris-contrib/examples"><img src="https://img.shields.io/badge/%20examples-repository-3362c2.svg?style=flat-square" alt="Examples"></a> <a href="https://github.com/iris-contrib/examples"><img src="https://img.shields.io/badge/%20examples-repository-3362c2.svg?style=flat-square" alt="Examples"></a>
@ -871,7 +871,7 @@ I recommend writing your API tests using this new library, [httpexpect](https://
Versioning Versioning
------------ ------------
Current: **v4.5.2** Current: **v4.5.3**
> Iris is an active project > Iris is an active project
@ -907,7 +907,7 @@ This project is licensed under the [MIT License](LICENSE), Copyright (c) 2016 Ge
[Travis]: http://travis-ci.org/kataras/iris [Travis]: http://travis-ci.org/kataras/iris
[License Widget]: https://img.shields.io/badge/license-MIT%20%20License%20-E91E63.svg?style=flat-square [License Widget]: https://img.shields.io/badge/license-MIT%20%20License%20-E91E63.svg?style=flat-square
[License]: https://github.com/kataras/iris/blob/master/LICENSE [License]: https://github.com/kataras/iris/blob/master/LICENSE
[Release Widget]: https://img.shields.io/badge/release-4.5.2%20-blue.svg?style=flat-square [Release Widget]: https://img.shields.io/badge/release-4.5.3%20-blue.svg?style=flat-square
[Release]: https://github.com/kataras/iris/releases [Release]: https://github.com/kataras/iris/releases
[Chat Widget]: https://img.shields.io/badge/community-chat%20-00BCD4.svg?style=flat-square [Chat Widget]: https://img.shields.io/badge/community-chat%20-00BCD4.svg?style=flat-square
[Chat]: https://kataras.rocket.chat/channel/iris [Chat]: https://kataras.rocket.chat/channel/iris

View File

@ -20,7 +20,6 @@ import (
"github.com/kataras/go-errors" "github.com/kataras/go-errors"
"github.com/kataras/go-fs" "github.com/kataras/go-fs"
"github.com/kataras/go-sessions" "github.com/kataras/go-sessions"
"github.com/kataras/iris/utils"
"github.com/valyala/fasthttp" "github.com/valyala/fasthttp"
) )
@ -202,12 +201,12 @@ func (ctx *Context) URLParamInt64(key string) (int64, error) {
// MethodString returns the HTTP Method // MethodString returns the HTTP Method
func (ctx *Context) MethodString() string { func (ctx *Context) MethodString() string {
return utils.BytesToString(ctx.Method()) return string(ctx.Method())
} }
// HostString returns the Host of the request( the url as string ) // HostString returns the Host of the request( the url as string )
func (ctx *Context) HostString() string { func (ctx *Context) HostString() string {
return utils.BytesToString(ctx.Host()) return string(ctx.Host())
} }
// VirtualHostname returns the hostname that user registers, host path maybe differs from the real which is HostString, which taken from a net.listener // VirtualHostname returns the hostname that user registers, host path maybe differs from the real which is HostString, which taken from a net.listener
@ -246,9 +245,9 @@ func (ctx *Context) PathString() string {
func (ctx *Context) RequestPath(escape bool) string { func (ctx *Context) RequestPath(escape bool) string {
if escape { if escape {
// return utils.BytesToString(ctx.RequestCtx.Path()) // return utils.BytesToString(ctx.RequestCtx.Path())
return utils.BytesToString(ctx.RequestCtx.URI().PathOriginal()) return string(ctx.RequestCtx.URI().PathOriginal())
} }
return utils.BytesToString(ctx.RequestCtx.RequestURI()) return string(ctx.RequestCtx.RequestURI())
} }
// RequestIP gets just the Remote Address from the client. // RequestIP gets just the Remote Address from the client.
@ -283,7 +282,7 @@ func (ctx *Context) RemoteAddr() string {
// accepts one parameter, the key of the header (string) // accepts one parameter, the key of the header (string)
// returns string // returns string
func (ctx *Context) RequestHeader(k string) string { func (ctx *Context) RequestHeader(k string) string {
return utils.BytesToString(ctx.RequestCtx.Request.Header.Peek(k)) return string(ctx.RequestCtx.Request.Header.Peek(k))
} }
// IsAjax returns true if this request is an 'ajax request'( XMLHttpRequest) // IsAjax returns true if this request is an 'ajax request'( XMLHttpRequest)

35
http.go
View File

@ -15,7 +15,6 @@ import (
"github.com/iris-contrib/letsencrypt" "github.com/iris-contrib/letsencrypt"
"github.com/kataras/go-errors" "github.com/kataras/go-errors"
"github.com/kataras/iris/utils"
"github.com/valyala/fasthttp" "github.com/valyala/fasthttp"
"github.com/valyala/fasthttp/fasthttpadaptor" "github.com/valyala/fasthttp/fasthttpadaptor"
) )
@ -434,6 +433,14 @@ func getParamsLen(path string) uint8 {
return uint8(n) return uint8(n)
} }
// findLower returns the smaller number between a and b
func findLower(a, b int) int {
if a <= b {
return a
}
return b
}
// add adds a muxEntry to the existing muxEntry or to the tree if no muxEntry has the prefix of // add adds a muxEntry to the existing muxEntry or to the tree if no muxEntry has the prefix of
func (e *muxEntry) add(path string, middleware Middleware) error { func (e *muxEntry) add(path string, middleware Middleware) error {
fullPath := path fullPath := path
@ -448,7 +455,7 @@ func (e *muxEntry) add(path string, middleware Middleware) error {
} }
i := 0 i := 0
max := utils.FindLower(len(path), len(e.part)) max := findLower(len(path), len(e.part))
for i < max && path[i] == e.part[i] { for i < max && path[i] == e.part[i] {
i++ i++
} }
@ -1073,11 +1080,11 @@ func (mux *serveMux) build() (getRequestPath func(*fasthttp.RequestCtx) string,
// optimize this once once, we could do that: context.RequestPath(mux.escapePath), but we lose some nanoseconds on if :) // optimize this once once, we could do that: context.RequestPath(mux.escapePath), but we lose some nanoseconds on if :)
getRequestPath = func(reqCtx *fasthttp.RequestCtx) string { getRequestPath = func(reqCtx *fasthttp.RequestCtx) string {
return utils.BytesToString(reqCtx.Path()) //string(ctx.Path()[:]) // a little bit of memory allocation, old method used: BytesToString, If I see the benchmarks get low I will change it back to old, but this way is safer. return string(reqCtx.Path())
} }
if !mux.escapePath { if !mux.escapePath {
getRequestPath = func(reqCtx *fasthttp.RequestCtx) string { return utils.BytesToString(reqCtx.RequestURI()) } getRequestPath = func(reqCtx *fasthttp.RequestCtx) string { return string(reqCtx.RequestURI()) }
} }
methodEqual = func(reqMethod []byte, treeMethod []byte) bool { methodEqual = func(reqMethod []byte, treeMethod []byte) bool {
@ -1109,6 +1116,22 @@ func (mux *serveMux) lookup(routeName string) *route {
return nil return nil
} }
//THESE ARE FROM Go Authors
var htmlReplacer = strings.NewReplacer(
"&", "&amp;",
"<", "&lt;",
">", "&gt;",
// "&#34;" is shorter than "&quot;".
`"`, "&#34;",
// "&#39;" is shorter than "&apos;" and apos was not in HTML until HTML5.
"'", "&#39;",
)
// HTMLEscape returns a string which has no valid html code
func HTMLEscape(s string) string {
return htmlReplacer.Replace(s)
}
// BuildHandler the default Iris router when iris.Handler is nil // BuildHandler the default Iris router when iris.Handler is nil
func (mux *serveMux) BuildHandler() HandlerFunc { func (mux *serveMux) BuildHandler() HandlerFunc {
@ -1168,7 +1191,7 @@ func (mux *serveMux) BuildHandler() HandlerFunc {
} }
context.Request.URI().SetPath(reqPath) context.Request.URI().SetPath(reqPath)
urlToRedirect := utils.BytesToString(context.Request.RequestURI()) urlToRedirect := string(context.Request.RequestURI())
statisForRedirect := StatusMovedPermanently // StatusMovedPermanently, this document is obselte, clients caches this. statisForRedirect := StatusMovedPermanently // StatusMovedPermanently, this document is obselte, clients caches this.
if bytes.Equal(tree.method, MethodPostBytes) || if bytes.Equal(tree.method, MethodPostBytes) ||
@ -1182,7 +1205,7 @@ func (mux *serveMux) BuildHandler() HandlerFunc {
// response because older user agents may not understand 301/307. // response because older user agents may not understand 301/307.
// Shouldn't send the response for POST or HEAD; that leaves GET. // Shouldn't send the response for POST or HEAD; that leaves GET.
if bytes.Equal(tree.method, MethodGetBytes) { if bytes.Equal(tree.method, MethodGetBytes) {
note := "<a href=\"" + utils.HTMLEscape(urlToRedirect) + "\">Moved Permanently</a>.\n" note := "<a href=\"" + HTMLEscape(urlToRedirect) + "\">Moved Permanently</a>.\n"
context.Write(note) context.Write(note)
} }
return return

View File

@ -79,7 +79,7 @@ import (
const ( const (
// Version is the current version of the Iris web framework // Version is the current version of the Iris web framework
Version = "4.5.2" Version = "4.5.3"
banner = ` _____ _ banner = ` _____ _
|_ _| (_) |_ _| (_)

View File

@ -1,120 +0,0 @@
package utils
import (
"bytes"
"encoding/base64"
"encoding/gob"
"math/rand"
"reflect"
"strings"
"time"
"unsafe"
)
//THESE ARE FROM Go Authors
var htmlReplacer = strings.NewReplacer(
"&", "&amp;",
"<", "&lt;",
">", "&gt;",
// "&#34;" is shorter than "&quot;".
`"`, "&#34;",
// "&#39;" is shorter than "&apos;" and apos was not in HTML until HTML5.
"'", "&#39;",
)
// HTMLEscape returns a string which has no valid html code
func HTMLEscape(s string) string {
return htmlReplacer.Replace(s)
}
// FindLower returns the smaller number between a and b
func FindLower(a, b int) int {
if a <= b {
return a
}
return b
}
// BytesToString accepts bytes and returns their string presentation
// instead of string() this method doesn't generate memory allocations,
// BUT it is not safe to use anywhere because it points
// this helps on 0 memory allocations
func BytesToString(b []byte) string {
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
sh := reflect.StringHeader{bh.Data, bh.Len}
return *(*string)(unsafe.Pointer(&sh))
}
// StringToBytes accepts string and returns their []byte presentation
// instead of byte() this method doesn't generate memory allocations,
// BUT it is not safe to use anywhere because it points
// this helps on 0 memory allocations
func StringToBytes(s string) []byte {
sh := (*reflect.StringHeader)(unsafe.Pointer(&s))
bh := reflect.SliceHeader{sh.Data, sh.Len, 0}
return *(*[]byte)(unsafe.Pointer(&bh))
}
//
const (
letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
letterIdxBits = 6 // 6 bits to represent a letter index
letterIdxMask = 1<<letterIdxBits - 1 // All 1-bits, as many as letterIdxBits
letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits
)
var src = rand.NewSource(time.Now().UnixNano())
// Random takes a parameter (int) and returns random slice of byte
// ex: var randomstrbytes []byte; randomstrbytes = utils.Random(32)
func Random(n int) []byte {
b := make([]byte, n)
// A src.Int63() generates 63 random bits, enough for letterIdxMax characters!
for i, cache, remain := n-1, src.Int63(), letterIdxMax; i >= 0; {
if remain == 0 {
cache, remain = src.Int63(), letterIdxMax
}
if idx := int(cache & letterIdxMask); idx < len(letterBytes) {
b[i] = letterBytes[idx]
i--
}
cache >>= letterIdxBits
remain--
}
return b
}
// RandomString accepts a number(10 for example) and returns a random string using simple but fairly safe random algorithm
func RandomString(n int) string {
return string(Random(n))
}
// Serialize serialize any type to gob bytes and after returns its the base64 encoded string
func Serialize(m interface{}) (string, error) {
b := bytes.Buffer{}
encoder := gob.NewEncoder(&b)
err := encoder.Encode(m)
if err != nil {
return "", err
}
return base64.StdEncoding.EncodeToString(b.Bytes()), nil
}
// Deserialize accepts an encoded string and a data struct which will be filled with the desierialized string
// using gob decoder
func Deserialize(str string, m interface{}) error {
by, err := base64.StdEncoding.DecodeString(str)
if err != nil {
return err
}
b := bytes.Buffer{}
b.Write(by)
d := gob.NewDecoder(&b)
// d := gob.NewDecoder(bytes.NewBufferString(str))
err = d.Decode(&m)
if err != nil {
return err
}
return nil
}