Hello everyone,
As the title suggests, I am attempting to test adding gzip compression to a connection to an application I am testing. Currently I have the application set up with httptunnel, which forwards the connection to the remote host.
I would like to use a script to intercept the connection between the application and httptunnel, gzip the data that is there, and then forward it on. On the other side, the opposite will happen with gzip -d, with the resulting data passed on to the server application.
However I need some help, as I am fairly new to some of the things which are required to do this, like mkfifo, as well as piping outputs. I think there may be some other problems implementing such an idea with multiple connections, but that is a problem for later.
I have created a connection which works fine for sending gz files, and a while loop to keep things going.
while true ; do nc -l 3333 | gzip -d ; done
and on the other side, simply
nc 192.168.20.84 3333 < a.gz
Can someone assist in developing this so that I can use this method to compress the connection on one side ,and decompress on the other side?
The following is an attempt to do what what needs to be done on one side, but on other, I am not so sure about decompressing and passing data on. httptunnel is listening on 8080 of course.
#!/bin/sh
mkfifo /tmp/gz.tmp
while true; do
cat gz.tmp | gzip | nc -l -k localhost 9123 | nc localhost 8080 ;
done
Secondly, I know that this will only compress data travelling in one direction. I would like to have the same idea operating in reverse, from the server back to the host. Would this be possible? This might be quite complicated, due to dynamic source ports. Having gzip know what to do with the data might be another problem. Perhaps attempting "gzip -d" first, then if it gives a fail code, just run "gzip". Is there a cleaner way of detecting gzip compression, if it is needed?
Any help would be greatly appreciated.