diff --git a/context/response_recorder.go b/context/response_recorder.go index 0157a94f..d32e1eeb 100644 --- a/context/response_recorder.go +++ b/context/response_recorder.go @@ -85,7 +85,9 @@ func (w *ResponseRecorder) EndResponse() { // possible to maximize compatibility. func (w *ResponseRecorder) Write(contents []byte) (int, error) { 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. diff --git a/core/router/api_builder.go b/core/router/api_builder.go index 17aa0352..1b176ca5 100644 --- a/core/router/api_builder.go +++ b/core/router/api_builder.go @@ -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 // 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 // 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 // (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 func (api *APIBuilder) StaticEmbeddedGzip(requestPath string, vdir string, gzipAssetFn func(name string) ([]byte, error), gzipNamesFn func() []string) *Route { diff --git a/core/router/fs.go b/core/router/fs.go index a8109ec5..65a41332 100644 --- a/core/router/fs.go +++ b/core/router/fs.go @@ -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 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,