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: 
philotas
Roku Guru

Escape (UrlEncode) within render thread without using roUrlTransfer?

I need to use the Escape function of roUrlTransfer to create a working URL.
However since the Escape function is tied to  roUrlTransfer I cannot create an object on the SG render thread.
And it is overkill to have to create a roUrlTransfer anyways .. especially in another thread just to manipulate a string.

So how can I use the Escape function? Shouldn't that function be a global function instead of belonging to ifUrlTransfer?
0 Kudos
9 REPLIES 9
EnTerr
Roku Guru

Re: Escape (UrlEncode) within render thread without using roUrlTransfer?

Hahaha, that's a good one!
You can't - sorry. 

As an excercise of ridiculousness, maybe create a persistent "UrlEncoder" Task thread, with "input" and "output" field, then put observer on the output and shove the URL in the input, wait for a call back... that'd be a good Karnapidasana
0 Kudos
RokuKC
Roku Employee
Roku Employee

Re: Escape (UrlEncode) within render thread without using roUrlTransfer?

"philotas" wrote:
I need to use the Escape function of roUrlTransfer to create a working URL.
However since the Escape function is tied to  roUrlTransfer I cannot create an object on the SG render thread.
And it is overkill to have to create a roUrlTransfer anyways .. especially in another thread just to manipulate a string.

So how can I use the Escape function? Shouldn't that function be a global function instead of belonging to ifUrlTransfer?


Thanks for raising the issue. I've filed a feature request for this.
0 Kudos
philotas
Roku Guru

Re: Escape (UrlEncode) within render thread without using roUrlTransfer?

"EnTerr" wrote:
Hahaha, that's a good one!
You can't - sorry. 

As an excercise of ridiculousness, maybe create a persistent "UrlEncoder" Task thread, with "input" and "output" field, then put observer on the output and shove the URL in the input, wait for a call back... that'd be a good Karnapidasana

haha, good one too! Sometimes feeling the same!
0 Kudos
EnTerr
Roku Guru

Re: Escape (UrlEncode) within render thread without using roUrlTransfer?

"philotas" wrote:
haha, good one too! Sometimes feeling the same!

Sadly, i could not come with a short and elegant workaround - or i would have suggested it. The fact that the (un)usually resourceful RokuKC and theEndless didn't either, also speaks.

You could write your own function that goes over the string character by character - and %-escape the ones that are not "unreserved". A roRegEx might come handy to check against, something like "[\w\d\-_.~]". And not to forget UTF8-escaping the ones with ASC() > 255 ... so nevermind, probably better to do roByteArray.FromAsciiString() and then toHexString() everything and insert % before every two chars... a rather bad way.
0 Kudos
EnTerr
Roku Guru

Re: Escape (UrlEncode) within render thread without using roUrlTransfer?

Here, i whipped a band-aid:
function url_encode(s):
unreserved = createObject("roRegex", "[\w\d\-_.]", "")
ba = createObject("roByteArray")
res = ""
for each ch in s.split(""):
if unreserved.isMatch(ch):
res += ch
else:
ba.fromAsciiString(ch): hex = ba.toHexString()
for i = 1 to len(hex) step 2: res += "%" + mid(hex,i,2): next
end if
next
return res
end function
0 Kudos
TheEndless
Channel Surfer

Re: Escape (UrlEncode) within render thread without using roUrlTransfer?

I'm curious about the use-case.  What is the situation in which you need to URL encode a value in a separate thread from the actual web request?
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
EnTerr
Roku Guru

Re: Escape (UrlEncode) within render thread without using roUrlTransfer?

"TheEndless" wrote:
I'm curious about the use-case.  What is the situation in which you need to URL encode a value in a separate thread from the actual web request?

Umm... i can easily see the need if using one of the media playback noids - "Audio" and "Video" (AKA the Roku bread and butter 8-) )?  

Say the media server for whatever reasons (security, analytics, accounting) requires you to pass it some varying magic either as a query or a cookie.or a header - and needing that url-encoded. Such needs will incur in the render thread, would it not?
0 Kudos
philotas
Roku Guru

Re: Escape (UrlEncode) within render thread without using roUrlTransfer?

"TheEndless" wrote:
I'm curious about the use-case.  What is the situation in which you need to URL encode a value in a separate thread from the actual web request?

I load data from a server in order to show images and text in a long row list.
Until the server is updated to deliver working URLs I need to construct the URL for the Poster component in the sg thread.
I could probably do the when loading the data, but then most of theses genereted URLs might never be used so it is not a good idea to prepare them "just in case".
0 Kudos
EnTerr
Roku Guru

Re: Escape (UrlEncode) within render thread without using roUrlTransfer?

Note for posterity: in 7.5, the issue has been resolved by adding new string methods: EncodeUriComponent(), DecodeUriComponent() and a couple more.
0 Kudos