Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
jbrave
Channel Surfer

Bug? getResponseHeadersArray(string feature)

According to the manual the correct syntax for getResponseHeadersArray is to have a string in the ().

Object GetResponseHeadersArray(String feature) 
• Returns an roArray of roAssociativeArrays. Each associative array contains a single
header name/value pair.


However any string I put in there gives me:

Member function not found in BrightScript Component or interface.

I was hoping I could get just one set of response headers, Set-Cookie (of which there are quite a few) instead of 58 headers which I will need to iterate through looking for that one Set-Cookie that contains the string I'm looking for. If it did work properly, I would still have to do some iteration, just not as much.

Seems that it only works with () instead of ("Set-Cookie") or any other text.

Documentation is on page 97 of the 2.7 SDK Component reference.

- Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
5 REPLIES 5
TheEndless
Channel Surfer

Re: Bug? getResponseHeadersArray(string feature)

Are there multiple "Set-Cookie" headers in the response? If not, you could just use the getResponseHeaders() method and access it directly.

I have a feeling the "String features" parameter is a copy/paste error.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
jbrave
Channel Surfer

Re: Bug? getResponseHeadersArray(string feature)

Yeah, a whole pile of set-cookies.

- Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
TheEndless
Channel Surfer

Re: Bug? getResponseHeadersArray(string feature)

If it helps, here's a function I wrote for one of my channels...
Function GetCookieValueFromHeaders( cookieName As String, headersArray As Object ) As String
cookieValue = ""
For Each header in headersArray
If header[ "Set-Cookie" ] <> invalid And header[ "Set-Cookie" ].InStr( cookieName + "=" ) = 0 Then
cookieValue = header[ "Set-Cookie" ].Mid( cookieName.Len() + 1 )
cookieValue = cookieValue.Mid( 0, cookieValue.InStr( ";" ) )
Exit For
End If
Next
Return cookieValue
End Function
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
jbrave
Channel Surfer

Re: Bug? getResponseHeadersArray(string feature)

Great timing!

works perfectly. Now to the question of why it works:

header["Set-Cookie"]

I didn't know you could do a lookup with an AssociativeArray using that notation! Yeah, it's on page 12 of the component reference...

Notatonal weirdness:

BrightScript Debugger> ?"hello world".instr("hello")
0
BrightScript Debugger> ?instr("hello world","hello")
1

instr is zero-based in first context, one based in the second context!

cookieValue = header[ "Set-Cookie" ].Mid( cookieName.Len() + 1 )
snip off the cookee name
cookieValue = cookieValue.Mid( 0, cookieValue.InStr( ";" ) )
snip off the string after the end of the cookie value and it's good to go!

I just came across this section of the Roku component reference earlier today (page 15/16 in 2.7), had never tried to use these functions in that way before today, synchronicity!

Thanks for your help!

- Joel
Screenshades: The first Screensaver for Roku2!
Musiclouds: The best free internet music, on your Roku!
Ouroborialis: Psychedelic Screensaver for Roku!
0 Kudos
TheEndless
Channel Surfer

Re: Bug? getResponseHeadersArray(string feature)

Funny... When I posted it, I said to myself, "I should probably put comments in here", but I'm far too lazy for that... 😉

There was a thread awhile back about the differences between the standalone versions of InStr and the instance versions (I think it's the same for Mid as well). If I had to guess, I'd say Roku went that route for familiarity for developers. For example, in VBScript InStr() is 1 based, whereas in VB.Net the .InStr() method is 0 based, so, if you're used to using VBScript, a 0 based InStr standalone function might confuse you, and vice versa if you used to using .Net. Total speculation, but it seems like a reasonable explanation to me...
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.