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

Panic if response has no status code set #254

Closed
ueffel opened this issue Sep 20, 2022 · 1 comment · Fixed by #255
Closed

Panic if response has no status code set #254

ueffel opened this issue Sep 20, 2022 · 1 comment · Fixed by #255

Comments

@ueffel
Copy link

ueffel commented Sep 20, 2022

Tested version: v1.6.20

I get a panic if I use the cache in combination with my image filter module.

As an example:

Build:

$ xcaddy build --with github.com/darkweak/souin/plugins/caddy --with github.com/ueffel/caddy-imagefilter/defaults

Config:

{
	debug
	order cache before rewrite
	order image_filter before file_server
	cache {
		nuts {
			configuration {
				dir cache
			}
		}
	}
}

http://:80 {
	cache
	image_filter {
		flip v
	}
}

Error:

2022/09/20 17:48:39.073 DEBUG   http.handlers.cache     Incoming request: &{Method:GET URL:/image.png Proto:HTTP/1.1 ProtoMajor:1 ProtoMinor:1 Header:map[Accept:[*/*] Date:[Tue, 20 Sep 2022 17:48:39 UTC] User-Agent:[curl/7.84.0]] Body:{} GetBody:<nil> ContentLength:0 TransferEncoding:[] Close:false Host:localhost Form:map[] PostForm:map[] MultipartForm:<nil> Trailer:map[] RemoteAddr:127.0.0.1:11057 RequestURI:/image.png TLS:<nil> Cancel:<nil> Response:<nil> ctx:0xc0004223c0}
2022/09/20 17:48:39.206 DEBUG   http.stdlib     http: panic serving 127.0.0.1:11057: invalid WriteHeader code 0
goroutine 114 [running]:
net/http.(*conn).serve.func1()
        net/http/server.go:1850 +0xbf
panic({0x1d6cd80, 0xc000842a30})
        runtime/panic.go:890 +0x262
net/http.checkWriteHeaderCode(...)
        net/http/server.go:1116
net/http.(*response).WriteHeader(0xc0005d80e0, 0x0)
        net/http/server.go:1150 +0x9db
github.com/darkweak/souin/plugins.(*CustomWriter).Send(0xc0002eff50)
        github.com/darkweak/souin@v1.6.20/plugins/base.go:86 +0x423
github.com/darkweak/souin/plugins.DefaultSouinPluginCallback({0x24ef040?, 0xc0002eff50?}, 0xc0004f0c00, {0x2502f50, 0xc0007fc240}, {0x0?, 0x0}, 0xc00062c6e0)
        github.com/darkweak/souin@v1.6.20/plugins/base.go:229 +0xa94
github.com/darkweak/souin/plugins/caddy.(*SouinCaddyPlugin).ServeHTTP(0xc0005b4000, {0x24f47d0?, 0xc0005d80e0}, 0xc0004f0600, {0x24e6360, 0xc0002ee750})
        github.com/darkweak/souin/plugins/caddy@v0.0.0-20220920124054-a2e88383a2bc/httpcache.go:129 +0x6a9
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapMiddleware.func1.1({0x24f47d0?, 0xc0005d80e0?}, 0x24e6360?)
        github.com/caddyserver/caddy/v2@v2.6.0/modules/caddyhttp/routes.go:290 +0x42
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0x24e6360?, {0x24f47d0?, 0xc0005d80e0?}, 0x8d42bb?)
        github.com/caddyserver/caddy/v2@v2.6.0/modules/caddyhttp/caddyhttp.go:58 +0x2f
github.com/caddyserver/caddy/v2/modules/caddyhttp.wrapRoute.func1.1({0x24f47d0, 0xc0005d80e0}, 0xc0004f0600)
        github.com/caddyserver/caddy/v2@v2.6.0/modules/caddyhttp/routes.go:259 +0x3a8
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc0002df000?, {0x24f47d0?, 0xc0005d80e0?}, 0x1ff1060?)
        github.com/caddyserver/caddy/v2@v2.6.0/modules/caddyhttp/caddyhttp.go:58 +0x2f
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).enforcementHandler(0x0?, {0x24f47d0?, 0xc0005d80e0?}, 0xc00050ab60?, {0x24e6360?, 0xc000910300?})
        github.com/caddyserver/caddy/v2@v2.6.0/modules/caddyhttp/server.go:370 +0x252
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).wrapPrimaryRoute.func1({0x24f47d0?, 0xc0005d80e0?}, 0x5a9717?)
        github.com/caddyserver/caddy/v2@v2.6.0/modules/caddyhttp/server.go:346 +0x3b
github.com/caddyserver/caddy/v2/modules/caddyhttp.HandlerFunc.ServeHTTP(0xc0005dda00?, {0x24f47d0?, 0xc0005d80e0?}, 0xc0004f0600?)
        github.com/caddyserver/caddy/v2@v2.6.0/modules/caddyhttp/caddyhttp.go:58 +0x2f
github.com/caddyserver/caddy/v2/modules/caddyhttp.(*Server).ServeHTTP(0xc000429b00, {0x24f47d0, 0xc0005d80e0}, 0xc0004f0600)
        github.com/caddyserver/caddy/v2@v2.6.0/modules/caddyhttp/server.go:282 +0xb55
net/http.serverHandler.ServeHTTP({0xc0002ee360?}, {0x24f47d0, 0xc0005d80e0}, 0xc0004f0400)
        net/http/server.go:2947 +0x30c
net/http.(*conn).serve(0xc000434b40, {0x24f66b0, 0xc0002ee210})
        net/http/server.go:1991 +0x607
created by net/http.(*Server).Serve
        net/http/server.go:3102 +0x4db

The problem seems to be, that the status code is not explicitly written in the image filter module. It just relies on the default status code 200 when writing to the response writer starts. I don't know if the panic is reproducible any other way, I expect so.

@darkweak
Copy link
Owner

I'm on it, I will force a 200 - HTTP OK.

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.

2 participants