Forum Discussion

Brad_53264's avatar
Brad_53264
Icon for Nimbostratus rankNimbostratus
Jun 27, 2012

Need help to translate line feeds (LF) into carriage returns (CR)

I have a client which is doing an HTTP GET on a plain text file. The plain text file contains line feeds (LF) on every line. I need an iRule solution that translates all line feeds into carriage returns (CR).

 

 

I am running version Big-IP 9.4.8.

 

 

Can someone help draft an iRule to accomplish this?

 

  • can you try to use stream profile and command something like the one Aaron sugguested in the discussion topic below?

     

     

    Remove Newlines in HTTP

     

    https://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/aft/19972/showtab/groupforums/Default.aspx
  • I've been trying to make that solution work, but have been unsuccessful. There are two types of requests that are made on this site. The first is a PROPFIND, no changes are needed to that request. The second is the GET which pulls down the plain text file. It is the plain text file that I need to have the line feeds converted to carriage returns.

     

     

    With the iRule implemented that you have linked my PROPFIND command does not get the expected results, and the GET never happens.

     

     

    Thanks in advance for your help.
  • With the iRule implemented that you have linked my PROPFIND command does not get the expected results, and the GET never happens.is it because stream command changes PROPFIND response content? if so, can you try to not enable stream on PRODFIND response e.g. save HTTP method to variable in HTTP_REQUEST and check it in HTTP_RESPONSE?
  • Here is what I have so far. PROPFIND is working correctly, GET is pulling down the files, but the content is empty.

    Thanks in advance for the help.

     
    
    when HTTP_REQUEST {
         set request_method [HTTP::method]
    }
    
    when HTTP_RESPONSE {
    
       if { $request_method contains "GET" }{
    
          STREAM::disable
    
          STREAM::expression {@\r\n@\r\n\r\n@}
          STREAM::enable
       }   
    }
    
    
  • STREAM:expression was used in the example from the link Nitass provided. I'm still struggling to come up with a working solution to this problem.

     

     

    Thanks in advance for the help.

     

  • I've solved this problem using the code below

     

     

    
    
    when HTTP_REQUEST {
    
        set request_method [HTTP::method]
    
     }
    
    when HTTP_RESPONSE {
    
       if { $request_method contains "GET" }{
         HTTP::collect [HTTP::header Content-Length]
          set clen [HTTP::header Content-Length]
        }
    }
    
    
    when HTTP_RESPONSE_DATA {
       if { $request_method contains "GET" }{
        regsub -all "\n" [HTTP::payload] "\r" newdata 
        HTTP::payload replace 0 $clen $newdata 
        HTTP::release 
    }
    }
    
     
  • cool!

     

     

    by the way, in HTTP_RESPONSE_DATA event, you may remove the if-condition because the event will be triggered by HTTP::collect which is only called for GET request.