Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trycf/b0008746f0d0158257086db3a462f18b to your computer and use it in GitHub Desktop.
Save trycf/b0008746f0d0158257086db3a462f18b to your computer and use it in GitHub Desktop.
TryCF Gist
<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