Windows has a mechanism that can look at the contents of a buffer and determine the appropriate content-type. The Microsoft site has an article that talks about how this works.
You can use the FindMimeFromData call to figure out what content-type to set when sending content via HTTP. Two important things to note:
- FindMimeFromData allocates the content-type buffer for you, but don't attempt to free it.
- The content-type comes back in Unicode.
The following code reads 256 or fewer bytes from a file, passes the buffer to FindMimeFromData and translates the content-type into ANSI.