mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
remove any trailing slash that may passed on StaticEmbeddedHandler (although all examples shows the correct way but you never know)
Former-commit-id: 50ab9ddb2e738b4061622ac9ebcfec30e0cdecfa
This commit is contained in:
parent
87036fdb6c
commit
8cec6a6f9b
|
@ -85,7 +85,9 @@ func (w *ResponseRecorder) EndResponse() {
|
||||||
// possible to maximize compatibility.
|
// possible to maximize compatibility.
|
||||||
func (w *ResponseRecorder) Write(contents []byte) (int, error) {
|
func (w *ResponseRecorder) Write(contents []byte) (int, error) {
|
||||||
w.chunks = append(w.chunks, contents...)
|
w.chunks = append(w.chunks, contents...)
|
||||||
return len(w.chunks), nil
|
// Remember that we should not return all the written length within `Write`:
|
||||||
|
// see https://github.com/kataras/iris/pull/931
|
||||||
|
return len(contents), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Writef formats according to a format specifier and writes to the response.
|
// Writef formats according to a format specifier and writes to the response.
|
||||||
|
|
|
@ -629,7 +629,7 @@ func (api *APIBuilder) StaticContent(reqPath string, cType string, content []byt
|
||||||
|
|
||||||
// StaticEmbedded used when files are distributed inside the app executable, using go-bindata mostly
|
// StaticEmbedded used when files are distributed inside the app executable, using go-bindata mostly
|
||||||
// First parameter is the request path, the path which the files in the vdir will be served to, for example "/static"
|
// First parameter is the request path, the path which the files in the vdir will be served to, for example "/static"
|
||||||
// Second parameter is the (virtual) directory path, for example "./assets"
|
// Second parameter is the (virtual) directory path, for example "./assets" (no trailing slash),
|
||||||
// Third parameter is the Asset function
|
// Third parameter is the Asset function
|
||||||
// Forth parameter is the AssetNames function.
|
// Forth parameter is the AssetNames function.
|
||||||
//
|
//
|
||||||
|
@ -646,6 +646,10 @@ func (api *APIBuilder) StaticEmbedded(requestPath string, vdir string, assetFn f
|
||||||
// it sends gzip response only, so the client must be aware that is expecting a gzip body
|
// it sends gzip response only, so the client must be aware that is expecting a gzip body
|
||||||
// (browsers and most modern browsers do that, so you can use it without fair).
|
// (browsers and most modern browsers do that, so you can use it without fair).
|
||||||
//
|
//
|
||||||
|
// First parameter is the request path, the path which the files in the vdir will be served to, for example "/static"
|
||||||
|
// Second parameter is the (virtual) directory path, for example "./assets" (no trailing slash),
|
||||||
|
// Third parameter is the GzipAsset function
|
||||||
|
// Forth parameter is the GzipAssetNames function.
|
||||||
//
|
//
|
||||||
// Example: https://github.com/kataras/iris/tree/master/_examples/file-server/embedding-gziped-files-into-app
|
// Example: https://github.com/kataras/iris/tree/master/_examples/file-server/embedding-gziped-files-into-app
|
||||||
func (api *APIBuilder) StaticEmbeddedGzip(requestPath string, vdir string, gzipAssetFn func(name string) ([]byte, error), gzipNamesFn func() []string) *Route {
|
func (api *APIBuilder) StaticEmbeddedGzip(requestPath string, vdir string, gzipAssetFn func(name string) ([]byte, error), gzipNamesFn func() []string) *Route {
|
||||||
|
|
|
@ -42,6 +42,14 @@ func StaticEmbeddedHandler(vdir string, assetFn func(name string) ([]byte, error
|
||||||
if vdir[0] == '/' || vdir[0] == os.PathSeparator { // second check for /something, (or ./something if we had dot on 0 it will be removed
|
if vdir[0] == '/' || vdir[0] == os.PathSeparator { // second check for /something, (or ./something if we had dot on 0 it will be removed
|
||||||
vdir = vdir[1:]
|
vdir = vdir[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check for trailing slashes because new users may be do that by mistake
|
||||||
|
// although all examples are showing the correct way but you never know
|
||||||
|
// i.e "./assets/" is not correct, if was inside "./assets".
|
||||||
|
// remove last "/".
|
||||||
|
if trailingSlashIdx := len(vdir) - 1; vdir[trailingSlashIdx] == '/' {
|
||||||
|
vdir = vdir[0:trailingSlashIdx]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// collect the names we are care for,
|
// collect the names we are care for,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user