Forum Discussion

EM's avatar
EM
Icon for Nimbostratus rankNimbostratus
Feb 03, 2018

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&para2=xyz';
        request.params.path = '/test';
        request.params.query = 'para1=abc&para2=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&param2=test2

The following incorrect server response is triggered:

 


    
        
    
    
    GET /test?param1=test1&param2=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?

 

  • Is there a particular reason you are using irules lx? standard irules are more efficient for what you are trying to do.

     

  • You can change the

    path
    ,
    uri
    and other parameters with the same setHeader function. Like this:

    flow.client.on("requestComplete", function(request) {
        request.setHeader('uri', '/test');
        request.setHeader('version', 'HTTP/1.0');
    
        request.complete();
    });