Roku Developer Program

Developers and content creators—a complete solution for growing an audience directly.
cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with roURLTransfer GetCookie API

Issue Description:
There is a issue with "getCookies" API in "roURLTransfer". This API is not returning back proper cookie object if the set-cookie header contains Max-Age parameter. The Max-Age parameter is very common in use in the recent past. So when server response header has cookies with Max-Age the cookie object returned in getCookies API is something as given below:
Cookie return object print:
<Component: roArray> =

<Component: roAssociativeArray> =
{
    Domain: "devunne.com"
    Name: "testcookie2"
    Path: "/"
    Value: "testing2"
    Version: 0
}
<Component: roAssociativeArray> =
{
    Domain: "devunne.com"
    Expires: <Component: roDateTime>
    Name: "Max-Age"
    Path: "/"
    Value: "36000000"
    Version: 0
}
<Component: roAssociativeArray> =
{
    Domain: "devunne.com"
    Name: "testcookie1"
    Path: "/"
    Value: "testing1"
    Version: 0
}
Test URL which returns cookies with Max-Age:
http://devunne.com/development/cookietest.php
In the above case you can see that the Max-Age is returned as another cookie object, and the actual cookies are not having any Expire time.
Code Snippet:
function AsyncRequest()

    url = "http://devunne.com/development/cookietest.php"
    xfer = CreateObject("roURLTransfer")
    port = CreateObject("roMessagePort")
    xfer.SetMessagePort(port)
    url = encodeUrlParams(url)
    xfer.EnableCookies()
    xfer.SetUrl(url)
    respData = invalid
    raw = invalid
    stat = xfer.AsyncGetToString()    
    print url
    if stat = true
        while (true)
            msg = wait(0, port)
            if (type(msg) = "roUrlEvent")
                code = msg.GetResponseCode()
                respData = invalid
                print "Response Code: "
                print code
                if (code = 200)
                    cookies = xfer.getCookies("", "/")                    
                    raw = msg.GetString()
                    print cookies
  
  
                                   
                else if (code < 0 )
                    xfer.AsyncCancel()                    
                endif
            else if (event = invalid)
                xfer.AsyncCancel()
            endif            
        end while
    endif    
end function
Understanding:
Its clearly issue with the API when there is Max-Age parameter added we have done extensive check regarding the issue. The problem does not occur if there is no Max-Age parameter in cookie. Below is the screenshot of the cookie from the browser.
0 Kudos
4 Replies
renojim
Level 8

Re: Issue with roURLTransfer GetCookie API

I see the same thing you do.  You could use GetResponseHeadersArray() and parse the headers/cookies yourself.

Brightscript Debugger> ?msg.getresponseheadersarray()
<Component: roArray> =
[
   <Component: roAssociativeArray>
   <Component: roAssociativeArray>
   <Component: roAssociativeArray>
   <Component: roAssociativeArray>
   <Component: roAssociativeArray>
   <Component: roAssociativeArray>
   <Component: roAssociativeArray>
   <Component: roAssociativeArray>
]

Brightscript Debugger> ha=msg.getresponseheadersarray()

Brightscript Debugger> ?ha[0]
<Component: roAssociativeArray> =
{
   Content-Length: "0"
}

Brightscript Debugger> ?ha[1]
<Component: roAssociativeArray> =
{
   Content-Type: "text/html; charset=UTF-8"
}

Brightscript Debugger> ?ha[2]
<Component: roAssociativeArray> =
{
   Date: "Fri, 19 Jan 2018 21:31:57 GMT"
}

Brightscript Debugger> ?ha[3]
<Component: roAssociativeArray> =
{
   Server: "Apache"
}

Brightscript Debugger> ?ha[4]
<Component: roAssociativeArray> =
{
   Set-Cookie: "testcookie1=testing1; Max-Age=6000000; Expires=Fri, 30 Mar 2018 08:11:57 GMT; Path=/; Domain=devunne.com"
}

Brightscript Debugger> ?ha[5]
<Component: roAssociativeArray> =
{
   Set-Cookie: "testcookie2=testing2; Max-Age=36000000; Expires=Tue, 12 Mar 2019 13:31:57 GMT; Path=/; Domain=devunne.com"
}

Brightscript Debugger> ?ha[6]
<Component: roAssociativeArray> =
{
   Vary: "User-Agent"
}

Brightscript Debugger> ?ha[7]
<Component: roAssociativeArray> =
{
   X-Powered-By: "PHP/5.6.32"
}

-JT
0 Kudos

Re: Issue with roURLTransfer GetCookie API

I could do that but still i think the problem with the GetCookie API needs to be sorted out on ROKU side, since the developers depending on the API might suddenly get wrong cookies based on the server response header having Max-Age as parameters, and everybody cannot keep manipulating the header.

And about the response header "Set-Cookie" manipulation there is a problem there as well: (roDateTime Problem)
The Set-cookie comes with Expires date time in this format "Sat, 03 Feb 2018 10:22:56 GMT" but roDateTime does not support this Datetime format.
 Because of which eventhough we parse and get the cookie we will not be able to form the Expiration roDateTime since the format is not supported.
 roDateTime supports only "YYYY-MM-DD HH:MMSmiley FrustratedS"
0 Kudos
renojim
Level 8

Re: Issue with roURLTransfer GetCookie API

I agree that it should be fixed, but I've always found it's easier to find a workaround for Roku bugs than to get Roku to fix or even acknowledge them. If your channel relies on Max-Age then you probably should start working on a method to mitigate the bug.

You should also report the bug to partnerSuccess@roku.com since it's becoming more and more rare that anyone from Roku responds in this forum.

-JT
0 Kudos
wizaro
Level 7

Re: Issue with roURLTransfer GetCookie API

Damn, I have the same problem, spent a day on this trying to figure it out.
Here is my original requested cookie and the one that I'm getting from the task content.
Note the missing "roDateTime" in Expires key when reading from the task content.

<Component: roAssociativeArray> =
{
    Domain: "domain.com"
    Expires: <Component: roDateTime>
    Name: "_uid"
    Path: "/"
    Value: "d5b8ad6917e35c667c3aed4fd6547"
    Version: 0
}

<Component: roAssociativeArray> =
{
    Domain: "domain.com"
    Expires: invalid
    Name: "_uid"
    Path: "/"
    Value: "d5b8ad6917e35c667c3aed4fd6547"
    Version: 0
}
0 Kudos