asynchttpPost header issue

When using "asynchttpPost" the response object type is "hubitat.scheduling.AsyncResponse"

I am trying to get the list of "set-cookie" headers from the http response, but the "AsyncResponse.getHeaders()" method returns a Map<String, String>. Headers can have multiple values, so the return type really needs to be Map<String, List>

I notice that the non-async "httpPost" function returns a "groovyx.net.http.HttpResponseDecorator" which allows full-featured and standard methods for accessing the headers. Does any way exist to get a "groovyx.net.http.HttpResponseDecorator" from a "hubitat.scheduling.AsyncResponse"?

Using async calls, how can I get all values for a multi-value header?

1 Like
metadata {
    definition (name: 'asynchttp bug', namespace: 'test', author: 'John Clark') {
        command 'testSync'
        command 'testAsync'
    }
}

def testSync() {
    httpGet([uri: 'http://www.google.com/']) { resp ->
        resp.getHeaders('Set-Cookie').eachWithIndex { value, i ->
            log.info "array element# ${i}] ${value}"
        }
    }
}

def testAsync() {
    asynchttpGet(testAsyncCallback, [uri: 'http://www.google.com/'])
}
def testAsyncCallback(resp, data) {
    def headers = resp.getHeaders()
    def setCookiesHeaderVal = headers['Set-Cookie']
    log.info "setCookiesHeaderVal type: ${setCookiesHeaderVal.class}"
    log.info "setCookiesHeaderVal: ${setCookiesHeaderVal}"
}

What data is actually in setCookiesHeaderVal in your example? Is it the map represented as a string somehow? The log output would be interesting to see.

curl -i www.google.com
HTTP/1.1 200 OK
Date: Thu, 15 Oct 2020 21:03:40 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server: gws
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
Set-Cookie: 1P_JAR=2020-10-15-21; expires=Sat, 14-Nov-2020 21:03:40 GMT; path=/; domain=.google.com; Secure
Set-Cookie: NID=204=kt0vhdfTE5OQwBgia3sf6Yo8eulUxc9XJCLBvGhl_6Q-QFYWhtXxZfL2NYmsylWsvJv3XSjta8XNic3fGUQpqIp4lTCsRqQ-TTwVXd7UPmSTLsJsULFRSLsf8cze6EplmLAPqCSa9i5CnWRfTZ6sC5P6a9xfLF9OM_WSN5-gWws; expires=Fri, 16-Apr-2021 21:03:40 GMT; path=/; domain=.google.com; HttpOnly
Accept-Ranges: none
Vary: Accept-Encoding
Transfer-Encoding: chunked

As we see there are two "Set-Cookie" headers in this call to google

Set-Cookie: 1P_JAR=2020-10-15-21; expires=Sat, 14-Nov-2020 21:03:40 GMT; path=/; domain=.google.com; Secure
Set-Cookie: NID=204=kt0vhdfTE5OQwBgia3sf6Yo8eulUxc9XJCLBvGhl_6Q-QFYWhtXxZfL2NYmsylWsvJv3XSjta8XNic3fGUQpqIp4lTCsRqQ-TTwVXd7UPmSTLsJsULFRSLsf8cze6EplmLAPqCSa9i5CnWRfTZ6sC5P6a9xfLF9OM_WSN5-gWws; expires=Fri, 16-Apr-2021 21:03:40 GMT; path=/; domain=.google.com; HttpOnly

The synchronus httpGet API lets me get the list of two:

2020-10-15 05:04:56.062 pm infoarray element# 1] Set-Cookie: NID=204=Yr9A1GrR93162PHDcOyj1KiY1oQSarF7pd2PGZn__Ixzl3eNDuAX-lGQ9OSAc1Kkg3zt68gLhU9aI-A5I615Ed8jsOOBy_PtIQHmNt9es6a4AwJzOPD-d87qO4zpJDAMpa0qq6-GbIgQXyTxGoyxPunNtApp3qpkP2bFs1XoJ3A; expires=Fri, 16-Apr-2021 21:04:55 GMT; path=/; domain=.google.com; HttpOnly
2020-10-15 05:04:56.049 pm infoarray element# 0] Set-Cookie: 1P_JAR=2020-10-15-21; expires=Sat, 14-Nov-2020 21:04:55 GMT; path=/; domain=.google.com; Secure

The asynchronous "asynchttGet" being a String value only allows access to the last one:

2020-10-15 05:09:57.121 pm [info](http://192.168.120.12/device/edit/99)setCookiesHeaderVal: NID=204=nDU1inOlKOwp5yJdMnlv42dLGr2ZKwIx8pSYJ2AXRyIBjXQa9skWQla8MRTENYsqiakMWduM6o420w3gZ5RCfszXt6UrxIo00HL-gwaaD4MovvP2Stlm7PApQJ2wal53-gmIvI0YfWumPSBN4GjuUCANGAHGdoT0pMBhCwtzJyE; expires=Fri, 16-Apr-2021 21:09:56 GMT; path=/; domain=.google.com; HttpOnly
Map<String, String> getHeaders()    A map of the headers returned from the call

communityhubitatcom/t/async-http-calls/1694

The problem is that getHeaders() needs to be returning a Map<String, List>

Yep, I was hoping that they might be mashed together in a way that you could parse them back out somehow. It seems like you need new/improved functionality from the Hubitat implementation. You'll have to ask someone like @mike.maxwell if there's any existing way to get at the full headers data or to make the request to add one.

You'll have to ask someone like @mike.maxwell if there's any existing way to get at the full headers data or to make the request to add one.

I am new to the board, how would I do this? Does he have an email listed somewhere? I opened a support case with Hubitat Wednesday but I have gotten no reply.

Since we both @ mentioned him, hopefully he'll see the post. You can also ask @bobbyD for help with raising visibility on your support request.

Did you ever get a solution for this or do I need to revert to using synchronous requests instead?