Created
November 13, 2018 17:28
-
-
Save trycf/b0008746f0d0158257086db3a462f18b to your computer and use it in GitHub Desktop.
TryCF Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
var response = { | |
mpegDASH: 'http://127.0.0.1:80/foo/bar?baz=hoge', | |
appleHLS: 'http://127.0.0.1:80/foo/bar?baz=hoge', | |
adobeRTMP: 'rtmp://127.0.0.1:80/foo/bar?baz=hoge', | |
adobeHDS: 'http://127.0.0.1:80/foo/bar?baz=hoge', | |
rtsp: 'rtsp://127.0.0.1:80/foo/bar?baz=hoge', | |
test1: 'http://127.0.0.1/foo/bar?baz=hoge', | |
test2: ':http://127.0.0.1/foo/bar?baz=hoge', | |
}; | |
WriteDump(label='Original response', var=response); | |
for (var key in response) { | |
var sourceUrl = response[key]; | |
var matches = REFind('^([^:]+:)//[^:/]+(:\d*)?', sourceUrl, 1, true); | |
// Don't alter source URLs which don't match. | |
if (matches.pos[1] == 0) { | |
continue; | |
} | |
var scheme = Left(sourceUrl, matches.len[2]); | |
var port = ''; | |
var path = Right(sourceUrl, -matches.len[1]); | |
if (scheme == 'http:') { | |
scheme = ''; | |
} else if (matches.pos[3] != 0) { | |
port = Mid(sourceUrl, matches.pos[3], matches.len[3]); | |
} | |
response[key] = (scheme & '//example.com' & port & path); | |
} | |
WriteDump(label='Modified response', var=response); | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment