Forum Discussion
bigben932_22424
Apr 24, 2017Altostratus
HTML5 WebSocket rewriting
I am having an issue with rewriting my WebSocket connection. Let me explain my scenario, and then I will explain the issue I am experiencing.
On my Internal network (192.168.252.x) I have a HTM...
bigben932_22424
Dec 21, 2017Altostratus
Hi Nolan,
So I did resolve this issue. I was in direct contact with F5 and they gave me an iRule to try, which I will post below. Since this was a few months back, all I remember was that I was still having some issues with this iRule and I ended up just using Version 13. Version 13 handles this natively and is much nicer to develop with.
Here is the iRule I received from F5:
when HTTP_RESPONSE_RELEASE {
ID560601: [Portal Access] Support for HTML5 video loaded with Media Source Extensions
Allow access to blob: scheme URLs
if { [HTTP::header exists Content-Security-Policy] } {
HTTP::header replace Content-Security-Policy \
[string map {"data:" "data: blob:"} [HTTP::header Content-Security-Policy]]
}
`
}
when ACCESS_ACL_ALLOWED {
ID470231: [RFE][Portal Access] WebSocket support
Experimental code for wrapping WebSocket constructor and disabling plugins for WS response
Tested on: IE11, Chrome, Firefox, Safari 9.1
`if { [HTTP::path] ends_with "/AccessNow/ericom.min.js" } {
`
log local0. "Injecting WebSocket helper into [HTTP::host][HTTP::uri]"
` set inject_ws_helper 1
HTTP::header remove Accept-Encoding
if { [HTTP::version] eq "1.1" } {
if { [HTTP::header is_keepalive] } {
HTTP::header replace "Connection" "Keep-Alive"
}
HTTP::version "1.0"
}
} elseif { [info exists inject_ws_helper] } {
unset inject_ws_helper
}
}
when REWRITE_REQUEST_DONE {
if { [HTTP::header exists Upgrade] && \
[string tolower [HTTP::header Upgrade]] contains "websocket" } {
REWRITE::disable
}
}
when HTTP_RESPONSE {
if { [info exists inject_ws_helper] } {
HTTP::collect 32
}
}
when HTTP_RESPONSE_DATA {
if { [info exists inject_ws_helper] } {
unset inject_ws_helper
HTTP::payload replace 0 0 {
(function() {
function F5_Wrap_WebSocket(F5_orig) {
var origin = 'F5_origin=' +
(location.protocol + '//' + location.host)
.replace(/./g,
function(c){return c.charCodeAt(0).toString(16)}
) +
'&F5CH=I';
var wrapper = function WebSocket(url) {
var orig_url = url;
if (arguments.length > 0) {
url = F5_WrapURL((url+'').replace(/^ws/i,'http'), 'I')
.replace(/^http/i,'ws')
.replace('F5CH=I', origin);
}
var socket = (arguments.length > 1) ?
new F5_orig(url, arguments[1]):
new F5_orig(url);
Object.defineProperty(socket, 'url', {
get: function(){return orig_url;}
});
return socket;
};
if (Object.setPrototypeOf) {
Object.setPrototypeOf(wrapper, F5_orig);
} else { // IE10
var keys = Object.keys(F5_orig);
for (var i = 0; i < keys.length; ++i) {
wrapper[keys[i]] = F5_orig[keys[i]];
}
}
wrapper.F5_original = F5_orig;
wrapper.prototype = F5_orig.prototype;
Object.defineProperty(wrapper.prototype, 'constructor', {
value: wrapper, writable: false, enumerable: false
});
wrapper.toString = function toString() { return F5_orig.toString();};
return wrapper;
}
if ((typeof(self.MozWebSocket) !== 'undefined') &&
!self.MozWebSocket.F5_original) {
self.MozWebSocket = F5_Wrap_WebSocket(self.MozWebSocket)
}
if ((typeof(self.WebSocket) !== 'undefined') &&
!self.WebSocket.F5_original) {
self.WebSocket = F5_Wrap_WebSocket(self.WebSocket)
}
})();
}
}
}
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects