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

Overriding MIME Types doesn't work #370

Closed
vadim-hleif opened this issue Aug 15, 2018 · 3 comments · Fixed by #374
Closed

Overriding MIME Types doesn't work #370

vadim-hleif opened this issue Aug 15, 2018 · 3 comments · Fixed by #374
Assignees
Labels

Comments

@vadim-hleif
Copy link

vadim-hleif commented Aug 15, 2018

Works

type of content the same as in Content-Type response header:

  • gomplate -d config=http://private-30833-vadimhleif.apiary-mock.com/yaml -i '{{ (ds "config").name }}'

Don't work

type of content not the same as in Content-Type response header, overriding MIME doesn't work:

  • gomplate -d config=http://private-30833-vadimhleif.apiary-mock.com/text -i '{{ (ds "config").name }}' don't work, expected
  • gomplate -d config=http://private-30833-vadimhleif.apiary-mock.com/text?type=application/yaml -i '{{ (ds "config").name }}'don't work, not expected

capture

what

It may be helpful. for example, for github api:

  • https://raw.githubusercontent.com/cloudposse/geodesic/master/README.yaml

why

  • Github return resource with text/plain content-Type and gomplate can't parse yaml

references

@hairyhenderson
Copy link
Owner

Hi @vadim-hleif, thanks for reporting this! I can confirm this behaviour, and based on how I wrote it, it makes sense - the URL query string gets parsed long before the Content-Type header is seen, so in effect, the Content-Type header always overrides anything provided in the URL.

I'd tend to agree with you that it's a bug, since the express purpose of the ?type=application/yaml query string is to force the type.

My initial feeling on precedence is: path extension, Content-Type header, then finally, type query.

This wouldn't help you in the case of the GitHub URL provided, since the Content-Type would still take precedence over the path extension. That being said, the raw.githubusercontent.com host will only return text/plain for non-binary files, which I seem to recall is by design (but can't find the reference right now)...

An option in the GitHub case is to use their contents API. It's a bit of a kludge but it's more predictable:

$ gomplate -d gh=https://api.github.com/repos/cloudposse/geodesic/contents/README.yaml -i '{{ ((ds "gh").content | base64.Decode | data.YAML).name }}'
Geodesic

Either way, ?type should have precedence over Content-Type, so I'll fix that.

@vadim-hleif
Copy link
Author

@hairyhenderson Hello, could you release this changes soon? Thank you!

@hairyhenderson
Copy link
Owner

My apologies @vadim-hleif! I'll see if I can get a release out today or this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants