mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-09-26 19:46:43 +02:00
Add support for client hints prefixed with Sec-CH-; Remove Viewport-Width header support
This commit is contained in:
@@ -1087,17 +1087,21 @@ func defaultProcessingOptions(headers http.Header) (*ProcessingOptions, error) {
|
||||
}
|
||||
|
||||
if config.EnableClientHints {
|
||||
if headerDPR := headers.Get("DPR"); len(headerDPR) > 0 {
|
||||
headerDPR := headers.Get("Sec-CH-DPR")
|
||||
if len(headerDPR) == 0 {
|
||||
headerDPR = headers.Get("DPR")
|
||||
}
|
||||
if len(headerDPR) > 0 {
|
||||
if dpr, err := strconv.ParseFloat(headerDPR, 64); err == nil && (dpr > 0 && dpr <= maxClientHintDPR) {
|
||||
po.Dpr = dpr
|
||||
}
|
||||
}
|
||||
if headerViewportWidth := headers.Get("Viewport-Width"); len(headerViewportWidth) > 0 {
|
||||
if vw, err := strconv.Atoi(headerViewportWidth); err == nil {
|
||||
po.Width = vw
|
||||
}
|
||||
|
||||
headerWidth := headers.Get("Sec-CH-Width")
|
||||
if len(headerWidth) == 0 {
|
||||
headerWidth = headers.Get("Width")
|
||||
}
|
||||
if headerWidth := headers.Get("Width"); len(headerWidth) > 0 {
|
||||
if len(headerWidth) > 0 {
|
||||
if w, err := strconv.Atoi(headerWidth); err == nil {
|
||||
po.Width = imath.Scale(w, 1/po.Dpr)
|
||||
}
|
||||
|
@@ -439,40 +439,6 @@ func (s *ProcessingOptionsTestSuite) TestParsePathWidthHeaderRedefine() {
|
||||
require.Equal(s.T(), 150, po.Width)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathViewportWidthHeader() {
|
||||
config.EnableClientHints = true
|
||||
|
||||
path := "/plain/http://images.dev/lorem/ipsum.jpg@png"
|
||||
headers := http.Header{"Viewport-Width": []string{"100"}}
|
||||
po, _, err := ParsePath(path, headers)
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
|
||||
require.Equal(s.T(), 100, po.Width)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathViewportWidthHeaderDisabled() {
|
||||
path := "/plain/http://images.dev/lorem/ipsum.jpg@png"
|
||||
headers := http.Header{"Viewport-Width": []string{"100"}}
|
||||
po, _, err := ParsePath(path, headers)
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
|
||||
require.Equal(s.T(), 0, po.Width)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathViewportWidthHeaderRedefine() {
|
||||
config.EnableClientHints = true
|
||||
|
||||
path := "/width:150/plain/http://images.dev/lorem/ipsum.jpg@png"
|
||||
headers := http.Header{"Viewport-Width": []string{"100"}}
|
||||
po, _, err := ParsePath(path, headers)
|
||||
|
||||
require.Nil(s.T(), err)
|
||||
|
||||
require.Equal(s.T(), 150, po.Width)
|
||||
}
|
||||
|
||||
func (s *ProcessingOptionsTestSuite) TestParsePathDprHeader() {
|
||||
config.EnableClientHints = true
|
||||
|
||||
|
Reference in New Issue
Block a user