GoogleCloudPlatform / gsutil

A command line tool for interacting with cloud storage services.
Apache License 2.0
878 stars 336 forks source link

Wrong Content-Type header for UTF-8 files #334

Open fjakobs opened 8 years ago

fjakobs commented 8 years ago

I have an UTF-8 encoded Javascript file, which I want to serve as a static asset from a GCS bucket. The problem is that the file always has content-type:application/javascript while it should be content-type:application/javascript; charset=utf-8.

I've tried using use_magicfile = True but that doesn't help either because the file command is called with --mime-type instead of the --mime argument which would include the charset http://linux.die.net/man/1/file.

The fix would be as easy as changing the argument here:

https://github.com/GoogleCloudPlatform/gsutil/blob/34571ffcdb82383e1a9144f9744fc8b5b97b5fdb/gslib/copy_helper.py#L1317

fjakobs commented 8 years ago

Just found that even if use_magicfile = True is fixed I'd still have a problem because file detects my JavaScript file as text/plain. It would be ideal if gsutil would detect the charset itelf e.g. using https://github.com/chardet/chardet.

thobrla commented 8 years ago

Thanks for the report. As a workaround in the meantime, you can use the gsutil setmeta command, or, when uploading the Javascript file with cp, use the global -h argument: -h 'Content-Type:application/javascript;charset=utf-8'

fjakobs commented 8 years ago

Thanks for the suggestion. For me this doesn't work because I'm uploading folders with different file types. I had to resort to a hacky wrapper around the file utility.