EM
Feb 03, 2018Nimbostratus
HTTP Rewrite from ILXPlugin
Hi DevCentral community!
I am currently trying to develop an iRule ILXPlugin, which is capable of rewriting the destination URL of the client request (including destination HOST, URI, PATH, QUERY) before sending it further to the respective backend server.
I have tried the following code below:
plugin.on('connect', function(flow) {
flow.client.on('requestComplete', function(request) {
var destinationHost = request.params.headers.host;
var requestMethod = request.params.method;
request.params.uri = '/test?para1=abc¶2=xyz';
request.params.path = '/test';
request.params.query = 'para1=abc¶2=xyz';
request.setHeader('testheader', 'myvalue');
flow.client.allow();
request.complete();
});
});
However, even though printing request.params shows the correctly rewritten values, the incorrect HOST, URI, PATH and QUERY is still sent to the backend.
As an example, when a client sends the following GET request:
https://host1.test.com/test?param1=test1¶m2=test2
The following incorrect server response is triggered:
GET /test?param1=test1¶m2=test2
Host: host1.test.com
Connection: keep-alive
Cache-Control: no-cache
testheader: myvalue
As it can be seen the old URL information is still sent to the backend, however the newly inserted header is present.
Is there any way to achieve this rewrite functionality?