Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

need fix Advanced Configuration cache error #1

Closed
a495433 opened this issue Jan 12, 2023 · 5 comments · Fixed by darkweak/souin#302
Closed

need fix Advanced Configuration cache error #1

a495433 opened this issue Jan 12, 2023 · 5 comments · Fixed by darkweak/souin#302

Comments

@a495433
Copy link

a495433 commented Jan 12, 2023

I downloaded caddy and image-filter on January 23, 2022 when I used Examples

{
    order image_ filter before file_ server
}

@thumbnail {

    path_ regexp thumb /.+\. (jpg|jpeg|png|gif|bmp|tif|tiff|webp)$

    query w=*

    query h=*

}

image_ filter @thumbnail {

    fit {query.w} {query.h}

}

The code does not respond correctly

Change to the bottom so that you can respond to the request correctly


{
    order image_ filter before file_ server
}

http://localtest.xxx.cn {

    root * D:/GitHub/dist

    route {

        reverse_ proxy /api/* http://192.168.1.123:1205

        try_ files {path} /index.html

        file_ server

   }

   @thumbnail {

        path_ regexp thumb /.+\. (jpg|jpeg|png|gif|bmp|tif|tiff|webp)$

        query w=*

        query h=*

  }


    handle @thumbnail {

    image_ filter {

        fit {query.w} {query.h}

    }

}

Download caddy, image-filter and cache in the introduction again

Error in code in Advanced Configuration after enabling cache

{

order image_ filter before file_ server

order cache before rewrite

}

http://localtest.xxx.cn {

    root * D:/GitHub/dist

    route {

        reverse_ proxy /api/* http://192.168.1.123:1205

        try_ files {path} /index.html

        file_ server

    }

    @thumbnail {

        path_ regexp thumb /.+\. (jpg|jpeg|png|gif|bmp|tif|tiff|webp)$

    }

    handle @thumbnail {

        reverse_ proxy [::1]:9000 # prevents multiple "Server: Caddy" response header

    }

}



http://:9000 { # internal address only accessable from the server itself to transform images

   bind ::1 # local ipv6 address (same as 127.0.0.1 for ipv4)

    #cache {

        #ttl 1000s

    #}



#header Cache-Control "max-age=86400" # keep 1 day in cache

    root D:/GitHub/dist

    @thumbnail {

         path_ regexp thumb /.+\. (jpg|jpeg|png|gif|bmp|tif|tiff|webp)$

    }

    handle @thumbnail {

        image_ filter {

            fit {query.w} {query.h}

        }

    }

}
@ueffel
Copy link
Owner

ueffel commented Jan 12, 2023

I downloaded caddy and image-filter on January 23, 2022 when I used Examples

{
    order image_ filter before file_ server
}

@thumbnail {

    path_ regexp thumb /.+\. (jpg|jpeg|png|gif|bmp|tif|tiff|webp)$

    query w=*

    query h=*

}

image_ filter @thumbnail {

    fit {query.w} {query.h}

}

The code does not respond correctly

Change to the bottom so that you can respond to the request correctly


{
    order image_ filter before file_ server
}

http://localtest.xxx.cn {

    root * D:/GitHub/dist

    route {

        reverse_ proxy /api/* http://192.168.1.123:1205

        try_ files {path} /index.html

        file_ server

   }

   @thumbnail {

        path_ regexp thumb /.+\. (jpg|jpeg|png|gif|bmp|tif|tiff|webp)$

        query w=*

        query h=*

  }


    handle @thumbnail {

    image_ filter {

        fit {query.w} {query.h}

    }

}

You're right. It is just a config snippet, not a complete usable Caddyfile. I will change that, so that at least the 2 examples at the top are complete.

Download caddy, image-filter and cache in the introduction again

Error in code in Advanced Configuration after enabling cache

{

order image_ filter before file_ server

order cache before rewrite

}

http://localtest.xxx.cn {

    root * D:/GitHub/dist

    route {

        reverse_ proxy /api/* http://192.168.1.123:1205

        try_ files {path} /index.html

        file_ server

    }

    @thumbnail {

        path_ regexp thumb /.+\. (jpg|jpeg|png|gif|bmp|tif|tiff|webp)$

    }

    handle @thumbnail {

        reverse_ proxy [::1]:9000 # prevents multiple "Server: Caddy" response header

    }

}



http://:9000 { # internal address only accessable from the server itself to transform images

   bind ::1 # local ipv6 address (same as 127.0.0.1 for ipv4)

    #cache {

        #ttl 1000s

    #}



#header Cache-Control "max-age=86400" # keep 1 day in cache

    root D:/GitHub/dist

    @thumbnail {

         path_ regexp thumb /.+\. (jpg|jpeg|png|gif|bmp|tif|tiff|webp)$

    }

    handle @thumbnail {

        image_ filter {

            fit {query.w} {query.h}

        }

    }

}

You are right, there is a panic:

panic: assignment to entry in nil map

goroutine 121 [running]:
net/textproto.MIMEHeader.Set(...)
        net/textproto/header.go:22
net/http.Header.Set(...)
        net/http/header.go:40
github.com/darkweak/souin/plugins.(*CustomWriter).Write(0xc00089ec00, {0xc00004cbc0, 0x8, 0x8})
        github.com/darkweak/souin@v1.6.27/plugins/base.go:79 +0x2ce
io.WriteString({0x2363d903f98, 0xc00089ec00}, {0x28c86ea, 0x8})
        io/io.go:315 +0x91
image/png.(*Encoder).Encode(0xc000981fe0, {0x2363d903f98?, 0xc00089ec00}, {0x2cfb340, 0xc0000ae440})
        image/png/writer.go:628 +0x527
github.com/disintegration/imaging.Encode({0x2363d903f98, 0xc00089ec00}, {0x2cfb340?, 0xc0000ae440?}, 0x1, {0xc00011b160, 0x2, 0xb439d7?})
        github.com/disintegration/imaging@v1.6.2/io.go:237 +0x287
github.com/ueffel/caddy-imagefilter.(*ImageFilter).ServeHTTP(0xc0006ac780, {0x2cf5f70?, 0xc00089ec00}, 0xc0000e0900, {0x0?, 0x1?})
        github.com/ueffel/caddy-imagefilter@v1.3.0/imagefilter.go:374 +0xd25
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapMiddleware.func1.1({0x2cf5f70?, 0xc00089ec00?}, 0xc000ccf541?)
        github.com/caddyserver/caddy/v2@v2.6.2/modules/caddyhttp/routes.go:290 +0x42
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0x0?, {0x2cf5f70?, 0xc00089ec00?}, 0x1?)
        github.com/caddyserver/caddy/v2@v2.6.2/modules/caddyhttp/caddyhttp.go:58 +0x2f
github.com/caddyserver/caddy/v2/modules/caddyhttp/headers.Handler.ServeHTTP({0xc00089b470?, 0x0?}, {0x2cf5f70, 0xc00089ec00}, 0xc0000e0900, {0x2cec9c0, 0xc000cfe630})
        github.com/caddyserver/caddy/v2@v2.6.2/modules/caddyhttp/headers/headers.go:110 +0x2e2
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapMiddleware.func1.1({0x2cf5f70?, 0xc00089ec00?}, 0x2cec9c0?)
        github.com/caddyserver/caddy/v2@v2.6.2/modules/caddyhttp/routes.go:290 +0x42
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0x2cec9c0?, {0x2cf5f70?, 0xc00089ec00?}, 0x80?)
        github.com/caddyserver/caddy/v2@v2.6.2/modules/caddyhttp/caddyhttp.go:58 +0x2f
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapRoute.func1.1({0x2cf5f70, 0xc00089ec00}, 0xc0000e0900)
        github.com/caddyserver/caddy/v2@v2.6.2/modules/caddyhttp/routes.go:259 +0x3a8
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0x0?, {0x2cf5f70?, 0xc00089ec00?}, 0xc00068ab80?)
        github.com/caddyserver/caddy/v2@v2.6.2/modules/caddyhttp/caddyhttp.go:58 +0x2f
github.com/caddyserver/caddy/v2/modules/caddyhttp/rewrite.Rewrite.ServeHTTP({{0x0, 0x0}, {0xc0006a2228, 0x15}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0, ...}, ...}, ...)
        github.com/caddyserver/caddy/v2@v2.6.2/modules/caddyhttp/rewrite/rewrite.go:136 +0x3ff
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapMiddleware.func1.1({0x2cf5f70?, 0xc00089ec00?}, 0x2cec9c0?)
        github.com/caddyserver/caddy/v2@v2.6.2/modules/caddyhttp/routes.go:290 +0x42
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0x2cec9c0?, {0x2cf5f70?, 0xc00089ec00?}, 0x6?)
        github.com/caddyserver/caddy/v2@v2.6.2/modules/caddyhttp/caddyhttp.go:58 +0x2f
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapRoute.func1.1({0x2cf5f70, 0xc00089ec00}, 0xc0000e0900)
        github.com/caddyserver/caddy/v2@v2.6.2/modules/caddyhttp/routes.go:259 +0x3a8
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0x0?, {0x2cf5f70?, 0xc00089ec00?}, 0x0?)
        github.com/caddyserver/caddy/v2@v2.6.2/modules/caddyhttp/caddyhttp.go:58 +0x2f
github.com/caddyserver/cache-handler.(*SouinCaddyPlugin).ServeHTTP.func1({0x0?, 0x0?}, 0x0?)
        github.com/caddyserver/cache-handler@v0.4.0/httpcache.go:129 +0x62
github.com/darkweak/souin/plugins.DefaultSouinPluginCallback.func2({0x2cf5f70?, 0xc00089ec00?}, 0x0?)
        github.com/darkweak/souin@v1.6.27/plugins/base.go:210 +0x7a
created by github.com/darkweak/souin/plugins.DefaultSouinPluginCallback
        github.com/darkweak/souin@v1.6.27/plugins/base.go:206 +0x83b

That seems to be an error in the https://github.com/caddyserver/cache-handler or https://github.com/darkweak/souin code. You should report an issue there. Maybe @darkweak can help, if there is something wrong in the example config?

ueffel added a commit that referenced this issue Jan 12, 2023
make the examples complete, so they're runnable without change
@darkweak
Copy link

That's because you're not writing any headers in the response and you're not calling the WriteHeader responsewriter. I think I could patch on my side @ueffel and check if the response contains headers here https://github.com/darkweak/souin/blob/v1.6.27/plugins/base.go#L79.

@ueffel
Copy link
Owner

ueffel commented Jan 12, 2023

@darkweak It feels a lot like darkweak/souin#254

It's still the same issue. Calling the Response.Write without explicit WriteHeader first.

@a495433
Copy link
Author

a495433 commented Jan 12, 2023

I see. Thank you for your answer

@ueffel
Copy link
Owner

ueffel commented Jan 21, 2023

Fixed in
github.com/darkweak/souin v1.6.28
github.com/darkweak/souin/plugins/caddy v0.0.0-20230121143516-b10614751e4b

@ueffel ueffel closed this as completed Jan 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants