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

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.

Yeah, a whole pile of set-cookies.

  • Joel

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

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

Funny… When I posted it, I said to myself, “I should probably put comments in here”, but I’m far too lazy for that… :wink:

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…