mirror of
https://github.com/woodchen-ink/webp_server_go.git
synced 2025-07-18 21:52:01 +08:00
Merge pull request #58 from webp-sh/url_decode_fix
url with url-encoded character fix
This commit is contained in:
commit
1881ae83cc
@ -22,6 +22,7 @@ func TestWebpEncoder(t *testing.T) {
|
|||||||
// test error
|
// test error
|
||||||
err := webpEncoder("./pics/empty.jpg", webp, 80, true, nil)
|
err := webpEncoder("./pics/empty.jpg", webp, 80, true, nil)
|
||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
|
_ = os.Remove(webp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNonImage(t *testing.T) {
|
func TestNonImage(t *testing.T) {
|
||||||
@ -29,14 +30,10 @@ func TestNonImage(t *testing.T) {
|
|||||||
// test error
|
// test error
|
||||||
var err = webpEncoder("./pics/empty.jpg", webp, 80, true, nil)
|
var err = webpEncoder("./pics/empty.jpg", webp, 80, true, nil)
|
||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
|
_ = os.Remove(webp)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWriteFail(t *testing.T) {
|
|
||||||
// test permission denied
|
|
||||||
var webp = "/123.webp"
|
|
||||||
var err = webpEncoder("./pics/png.jpg", webp, 80, true, nil)
|
|
||||||
assert.NotNil(t, err)
|
|
||||||
}
|
|
||||||
func walker() []string {
|
func walker() []string {
|
||||||
var list []string
|
var list []string
|
||||||
_ = filepath.Walk("./pics", func(path string, info os.FileInfo, err error) error {
|
_ = filepath.Walk("./pics", func(path string, info os.FileInfo, err error) error {
|
||||||
|
@ -116,7 +116,7 @@ func TestChanErr(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGetRemoteImageInfo(t *testing.T) {
|
func TestGetRemoteImageInfo(t *testing.T) {
|
||||||
url := "http://github.com/favicon.ico"
|
url := "https://github.com/favicon.ico"
|
||||||
statusCode, etag := getRemoteImageInfo(url)
|
statusCode, etag := getRemoteImageInfo(url)
|
||||||
assert.NotEqual(t, "", etag)
|
assert.NotEqual(t, "", etag)
|
||||||
assert.Equal(t, statusCode, http.StatusOK)
|
assert.Equal(t, statusCode, http.StatusOK)
|
||||||
|
BIN
pics/太神啦.png
Normal file
BIN
pics/太神啦.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 328 KiB |
@ -16,7 +16,7 @@ func TestPrefetchImages(t *testing.T) {
|
|||||||
_ = os.Mkdir(fp, 0755)
|
_ = os.Mkdir(fp, 0755)
|
||||||
prefetchImages("./pics", "./prefetch", "80")
|
prefetchImages("./pics", "./prefetch", "80")
|
||||||
count := fileCount("./prefetch")
|
count := fileCount("./prefetch")
|
||||||
assert.Equal(t, 6, count)
|
assert.Equal(t, 7, count)
|
||||||
_ = os.RemoveAll(fp)
|
_ = os.RemoveAll(fp)
|
||||||
|
|
||||||
// concurrency
|
// concurrency
|
||||||
@ -24,6 +24,6 @@ func TestPrefetchImages(t *testing.T) {
|
|||||||
_ = os.Mkdir(fp, 0755)
|
_ = os.Mkdir(fp, 0755)
|
||||||
prefetchImages("./pics", "./prefetch", "80")
|
prefetchImages("./pics", "./prefetch", "80")
|
||||||
count = fileCount("./prefetch")
|
count = fileCount("./prefetch")
|
||||||
assert.Equal(t, 4, count)
|
assert.Equal(t, 5, count)
|
||||||
_ = os.RemoveAll(fp)
|
_ = os.RemoveAll(fp)
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -14,7 +15,7 @@ import (
|
|||||||
|
|
||||||
func convert(c *fiber.Ctx) error {
|
func convert(c *fiber.Ctx) error {
|
||||||
//basic vars
|
//basic vars
|
||||||
var reqURI = c.Path() // /mypic/123.jpg
|
var reqURI, _ = url.QueryUnescape(c.Path()) // /mypic/123.jpg
|
||||||
var rawImageAbs = path.Join(config.ImgPath, reqURI) // /home/xxx/mypic/123.jpg
|
var rawImageAbs = path.Join(config.ImgPath, reqURI) // /home/xxx/mypic/123.jpg
|
||||||
var imgFilename = path.Base(reqURI) // pure filename, 123.jpg
|
var imgFilename = path.Base(reqURI) // pure filename, 123.jpg
|
||||||
var finalFile string // We'll only need one c.sendFile()
|
var finalFile string // We'll only need one c.sendFile()
|
||||||
|
@ -28,6 +28,8 @@ func TestConvert(t *testing.T) {
|
|||||||
"http://127.0.0.1:3333/png.jpg": "image/webp",
|
"http://127.0.0.1:3333/png.jpg": "image/webp",
|
||||||
"http://127.0.0.1:3333/12314.jpg": "text/plain; charset=utf-8",
|
"http://127.0.0.1:3333/12314.jpg": "text/plain; charset=utf-8",
|
||||||
"http://127.0.0.1:3333/dir1/inside.jpg": "image/webp",
|
"http://127.0.0.1:3333/dir1/inside.jpg": "image/webp",
|
||||||
|
"http://127.0.0.1:3333/%e5%a4%aa%e7%a5%9e%e5%95%a6.png": "image/webp",
|
||||||
|
"http://127.0.0.1:3333/太神啦.png": "image/webp",
|
||||||
}
|
}
|
||||||
|
|
||||||
var testSafariLink = map[string]string{
|
var testSafariLink = map[string]string{
|
||||||
@ -119,7 +121,7 @@ func setupParam() {
|
|||||||
func requestToServer(url string, app *fiber.App, ua string) (*http.Response, []byte) {
|
func requestToServer(url string, app *fiber.App, ua string) (*http.Response, []byte) {
|
||||||
req := httptest.NewRequest("GET", url, nil)
|
req := httptest.NewRequest("GET", url, nil)
|
||||||
req.Header.Set("User-Agent", ua)
|
req.Header.Set("User-Agent", ua)
|
||||||
resp, _ := app.Test(req)
|
resp, _ := app.Test(req, 60000)
|
||||||
data, _ := ioutil.ReadAll(resp.Body)
|
data, _ := ioutil.ReadAll(resp.Body)
|
||||||
return resp, data
|
return resp, data
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
Name: webp-server
|
Name: webp-server
|
||||||
Version: 0.2.1
|
Version: 0.2.2
|
||||||
Release: 1%{?dist}
|
Release: 1%{?dist}
|
||||||
Summary: Go version of WebP Server. A tool that will serve your JPG/PNGs as WebP format with compression, on-the-fly.
|
Summary: Go version of WebP Server. A tool that will serve your JPG/PNGs as WebP format with compression, on-the-fly.
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ var (
|
|||||||
|
|
||||||
proxyMode bool
|
proxyMode bool
|
||||||
config Config
|
config Config
|
||||||
version = "0.2.1"
|
version = "0.2.2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user