mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-10 20:22:31 +02:00
Back to net/http
Month of testing and profiling show that fasthttp doesn't gives us significatnt profit in memory and performance while being incompatible with many third-side packages and http/2
This commit is contained in:
@@ -11,12 +11,11 @@ import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
type urlOptions map[string][]string
|
||||
@@ -234,7 +233,7 @@ func decodeBase64URL(parts []string) (string, string, error) {
|
||||
return "", "", errInvalidURLEncoding
|
||||
}
|
||||
|
||||
fullURL := fmt.Sprintf("%s%s", conf.BaseURL, imageURL)
|
||||
fullURL := fmt.Sprintf("%s%s", conf.BaseURL, string(imageURL))
|
||||
|
||||
if _, err := url.ParseRequestURI(fullURL); err != nil {
|
||||
return "", "", errInvalidImageURL
|
||||
@@ -259,7 +258,7 @@ func decodePlainURL(parts []string) (string, string, error) {
|
||||
if unescaped, err := url.PathUnescape(urlParts[0]); err == nil {
|
||||
fullURL := fmt.Sprintf("%s%s", conf.BaseURL, unescaped)
|
||||
if _, err := url.ParseRequestURI(fullURL); err == nil {
|
||||
return fmt.Sprintf("%s%s", conf.BaseURL, unescaped), format, nil
|
||||
return fullURL, format, nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -848,8 +847,11 @@ func parsePathBasic(parts []string, headers *processingHeaders) (string, *proces
|
||||
return url, po, nil
|
||||
}
|
||||
|
||||
func parsePath(ctx context.Context, rctx *fasthttp.RequestCtx) (context.Context, error) {
|
||||
path := string(rctx.Request.URI().PathOriginal())
|
||||
func parsePath(ctx context.Context, r *http.Request) (context.Context, error) {
|
||||
path := r.URL.RawPath
|
||||
if len(path) == 0 {
|
||||
path = r.URL.Path
|
||||
}
|
||||
parts := strings.Split(strings.TrimPrefix(path, "/"), "/")
|
||||
|
||||
if len(parts) < 3 {
|
||||
@@ -863,10 +865,10 @@ func parsePath(ctx context.Context, rctx *fasthttp.RequestCtx) (context.Context,
|
||||
}
|
||||
|
||||
headers := &processingHeaders{
|
||||
Accept: string(rctx.Request.Header.Peek("Accept")),
|
||||
Width: string(rctx.Request.Header.Peek("Width")),
|
||||
ViewportWidth: string(rctx.Request.Header.Peek("Viewport-Width")),
|
||||
DPR: string(rctx.Request.Header.Peek("DPR")),
|
||||
Accept: r.Header.Get("Accept"),
|
||||
Width: r.Header.Get("Width"),
|
||||
ViewportWidth: r.Header.Get("Viewport-Width"),
|
||||
DPR: r.Header.Get("DPR"),
|
||||
}
|
||||
|
||||
var imageURL string
|
||||
|
Reference in New Issue
Block a user