I have changed http.Handle("/css", http.FileServer(http.Dir("public"))) to http.Handle("/css", http.FileServer(http.Dir("./public")))
and everything is working fine but i want to know reason for this behaviour as all other files like images are don’t have “./” prepended before directory name and everything works fine
Also filserver serves files with respetive content-Type header I’ve used same in my example but it’s behaving differently for different file types
// If the response's Content-Type header is not set, ServeContent
// first tries to deduce the type from name's file extension and,
// if that fails, falls back to reading the first block of the content
// and passing it to DetectContentType.
DetectContentType implements the algorithm described at http://mimesniff.spec.whatwg.org/ to determine the Content-Type of the given data. It considers at most the first 512 bytes of data. DetectContentType always returns a valid MIME type: if it cannot determine a more specific one, it returns “application/octet-stream”.
What are the names of your CSS files? Do they have the extension .css?
If not, what do they contain in the first 512 bytes? Is this enought to know that they containt CSS and not some other language like C or JavaScript?
I’m not sure how the fallback to content sniffing works, but mime.TypeByExtension which is used in the first stage requires registry stuff on Windows, and is (or was) vulnerable to cross compilation damage or just lack of registry entries on the target computer. That is, at least on Windows this autodetection stuff was less reliable than I’d expected.
But I think that resulted in application/octet-stream as lutzhorn says. Are you sure this is not what you get? Maybe the browser is adding its own defaults on top of that.