[upload plugin] Use file_server afte post methode

Hi.

Please can you tell me your opinion about the comitted solution.

...
	if u.ResponseTemplate != "" {
		r.URL.Path = "/" + u.ResponseTemplate
		/*
		 * Change the POST method to GET that the following Fileserver
		 * does not complain about the POST method
		 */
		if r.Method == "POST" {
			r.Method = "GET"
		}
	}

	return next.ServeHTTP(w, r)
}

I would like to use the file_server module to deliver a response template. The only way I have seen to solve the issue is to change the method from POST to GET as the file_server sends a 405 with the POST method. This was figured out from @francislavoie Strange error 405 returned on upload · Issue #6 · git001/caddyv2-upload · GitHub , thanks for that help.

My question is now is the developed solution a valid one or is there a “better” solution.
Thank you for your opinion.

Regards
Alex

1 Like

Hmm, you could just directly serve the content yourself with http.ServeContent(), instead of relying on fallback to file_server.

The file_server directive is essentially just a fancy wrapper on top of http.ServeContent() anyway.

1 Like

Thank you that’s an option.

I like the work which was done in caddy/staticfiles.go at master · caddyserver/caddy · GitHub for security checks and error handling that’s one of the reason why I use this excellent module.

Can I load file_server as guest module ?
Looks like the method change is the minimal impact version, from my point of view.

Is that error stuff relevant though, when serving a upload template? A lot of the code in there is pretty irrelevant to your usecase I think. You’re not serving a directory, you don’t have to care about hidden files, index file fallback, URL canonicalization, encoding/precompression, Etag. The only thing left is Content-Type, but http.ServeContent already handles that if the file extension exists on the template filename (i.e. .html).

Okay thank you. I will give the http.ServeContent a try.
Thank you for your opinion and hints.

This topic was automatically closed after 30 days. New replies are no longer allowed.