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

Help: HTTP datasource do a HEAD call first? #2313

Open
MaxenceG2M opened this issue Feb 3, 2025 · 0 comments
Open

Help: HTTP datasource do a HEAD call first? #2313

MaxenceG2M opened this issue Feb 3, 2025 · 0 comments

Comments

@MaxenceG2M
Copy link

Hi,

I'd like to use gomplate with the discogs API as datasource. Each call fails in a 405 status:

$ gomplate -d discogs=https://api.discogs.com/releases/249504 -i 'Album ID: {{ (ds "discogs").id }}' -H "ip=User-Agent: curl"
Album ID: 23:44:12 ERR  err="renderTemplate: failed to render template <arg>: template: <arg>:1:14: executing \"<arg>\" at <ds \"discogs\">: error calling ds: couldn't read datasource 'discogs' (https://api.discogs.com/releases/249504): stat (url: \"https://api.discogs.com/\", name: \"releases/249504\"): http GET failed with status 405"
$ gomplate --context discogs=https://api.discogs.com/releases/249504 -i 'Album ID: {{ .discogs.id }}'
23:51:09 ERR  err="couldn't read datasource 'discogs' (https://api.discogs.com/releases/249504): stat (url: \"https://api.discogs.com/\", name: \"releases/249504\"): http GET failed with status 405"

The same curl call success without problems:

$ curl -XGET https://api.discogs.com/releases/249504 -H 'User-Agent: curl'
{"id":249504,"status":"Accepted","year":1987,"resource_url":"https://api.discogs.com/releases/249504","uri":"https://www.discogs.com/release/249504-Rick-Astley-Never-Gonna-Give-You-Up", ........}

To try to understand why this doesn't work, I simply started a http server with (with nothing, just for debug) and call it. Then, I can see an "HEAD" call on each execution:

$ python3 -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
---> Doing first call with datasource:  gomplate -d discogs=http://localhost:8000/ -i 'Album ID: {{ (ds "discogs").id }}'
127.0.0.1 - - [03/Feb/2025 23:49:17] "HEAD / HTTP/1.1" 200 -
127.0.0.1 - - [03/Feb/2025 23:49:17] "GET / HTTP/1.1" 200 -
---> Doing a second call with context: gomplate --context discogs=http://localhost:8000/test -i 'Album ID: {{ .discogs.id }}'
127.0.0.1 - - [03/Feb/2025 23:50:20] code 404, message File not found
127.0.0.1 - - [03/Feb/2025 23:50:20] "HEAD /test HTTP/1.1" 404 -

Indeed, when I call discogs with HEAD method I'm getting a 405:

$ curl -I https://api.discogs.com/releases/249508
HTTP/2 405
date: Mon, 03 Feb 2025 23:01:34 GMT
content-type: application/json
content-length: 32
allow: GET
strict-transport-security: max-age=15552000
x-discogs-ratelimit: 25
x-discogs-ratelimit-remaining: 22
x-discogs-ratelimit-used: 3
cf-cache-status: DYNAMIC
set-cookie: __cf_bm=4F.sXkQpYyugMP6Dp4xPzEXbx__012liQRmjtBaLEiE-1738623694-1.0.1.1-1ETVTuoP7LhR72sw1ZU3DKDHAkZLfSlcoxLNz3OJswVp4gZZigYmSd7HHyOiLS5JRbQDZI.qGatsE9UH0W81hQ; path=/; expires=Mon, 03-Feb-25 23:31:34 GMT; domain=.discogs.com; HttpOnly; Secure; SameSite=None
server: cloudflare
cf-ray: 90c60b2c1da7700b-CDG
alt-svc: h3=":443"; ma=86400

Is this behavior known? Is there any way to avoid this call?

Thank for your help :)

@MaxenceG2M MaxenceG2M changed the title HTTP datasource do a HEAD call? Help: HTTP datasource do a HEAD call? Feb 3, 2025
@MaxenceG2M MaxenceG2M changed the title Help: HTTP datasource do a HEAD call? Help: HTTP datasource do a HEAD call first? Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant