I could use some help parsing the headers of an HTTP GET response.
Here's the code that I've got so far for trying to get the value, but it doesn't work (errors below)
> httpGet(params) { resp ->
> LOG("HTTP GET Response: ${resp?.data} with status ${resp?.status}", 3, "debug")
> if(resp.status == 200) {
> def headers = resp?.getAllHeaders()
> LOG("headers: ${headers}", 3, "debug")
> if (headers && headers.getAt('X-RateLimit-Remaining')) {
> state.apiCallsLeft = headers.getAt('X-RateLimit-Remaining')
> }
> return resp?.data
> }
This produces:
_httpGet exception: Exception evaluating property 'X-RateLimit-Remaining' for java.util.Arrays$ArrayList, Reason: groovy.lang.MissingPropertyException: No such property: X-RateLimit-Remaining for class: org.apache.http.message.BufferedHeader
[debug] headers: [Date: Sat, 01 Jun 2024 22:48:11 GMT, Content-Type: application/json, Transfer-Encoding: chunked, Connection: keep-alive, Cache-Control: no-cache, no-store, max-age=0, must-revalidate, Pragma: no-cache, Expires: 0, X-XSS-Protection: 1; mode=block, X-Frame-Options: DENY, X-Content-Type-Options: nosniff, X-RateLimit-Limit: 1700, X-RateLimit-Remaining: 1268, X-RateLimit-Reset: 2024-06-02T00:00:00Z]
which looks like the headers print as an accessible groovy Map. But they are not accessible as a map it seems:
Exception Error: groovy.lang.MissingPropertyException: Exception evaluating property 'X-RateLimit-Remaining' for java.util.Arrays$ArrayList, Reason: groovy.lang.MissingPropertyException: No such property: X-RateLimit-Remaining for class: org.apache.http.message.BufferedHeader
And I can't figure out how to access a BufferedHeader either. Help?