Click here to Skip to main content
Click here to Skip to main content

HTTP Tunneling

, 14 Jun 2000
Rate this:
Please Sign up or sign in to vote.
This article describes how to open arbitrary TCP connections through proxy servers
<!-- Download Links -->
  • Download source files - 24 Kb
  • Download demo application - 87 Kb
  • <!-- Main HTML starts here -->


    The application discussed in this article provides the ability to make TCP connections through a proxy server. Often computers are behind firewalls that deny many connections. But HTTP connection is usually allowed and is made through a proxy server. This article will show how arbitrary TCP connections can be made using HTTP protocol and the proxy server.


    When an HTTP connection is made through a proxy server the client (usually the browser) sends the request to the proxy. The proxy opens the connection to the destination, sends the request, receives the response and sends it back to the client. The HTTP protocol specifies a request method called CONNECT. The CONNECT method can be used by the client to inform the proxy server that a connection to some host on some port is required. The proxy server, if allows such connections, tries to connect to the destination address specified in the request header. If it the operation fails it sends back to the client a negative HTTP response and close the connection. If the operation succeeded then send back an HTTP positive response and the connection is consider established. After that, the proxy does not care what data is transferred between client requesting the connection and the destination. It just forwards data in both ways acting as a tunnel.

    About the protocol

    We are interested in CONNECT method from the HTTP protocol. After the applications opens a connection with the proxy server it must send the connect request in the form of an HTTP request:

    CONNECT <destination_address>:<destination_port> <http_version><CR><LF>

    The proxy server process the request and try to make a connection to <destionation_address>:<destination_port>.

    The proxy server sends back an HTTP response in the form:

    <http_version> <code> <message><CR><LF>

    If it is a positive response (code=200) then after the empty line the proxy begins to acts as a tunnel and forwards data. If it is a negative response (code!=200) then connection is closed after the empty line.

    The HTTPTunneling application

    The application act as specified in a configuration file. An entry in the configuration file locks like this:

    <Source port> <Destination address> <Destination port> <Proxy address> <Proxy port>

    If the application is running and an entry in the configuration files changes, the application automatically updates itself.

    For every entry in the configuration file the application creates a port listener. This is a thread that opens a socket on <Source port> and waits for connection. When a request arrives on that port it tries to open a tunnel to the <Destination address>:< port>. If the <Proxy address> and <Proxy port> are missing, a direct connection is made. If the field are present it opens a connection to the proxy and sends a CONNECT request using the method specified above. The tunnel construction is made in a separate thread to let the port listener to accept immediatelly new connections. After the connection is established a tunnel object is constructed based on the opened sockets, sockets are marked as non-blocking and the object is passed to manager object. The thread that has created the tunnel is destroyed. Data transfer is made on a single thread. When one of the ends closes the connection the tunnel closes the other and the tunnel is marked as inactive. The manager finds the tunnel inactive and removes it from the list of active tunnels.

    By default the application generates log information in HTTPTunneling.log file. This file can be consulted to find wrong application behaviour.

    Known problems

    • If no data transfer is made the proxy could close the connection, event neither the initiator neither the destination has closed the connection.
    • Proxy authorization may be required. This can be easily solved including in the HTTP request the Proxy-Authorization field.


    June 15, 2000

    • Posted.


    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    About the Author

    Alex Turc

    United States United States
    No Biography provided

    Comments and Discussions

    Generalvoip ocx , voip activex , voip lib Pinsusshasnat ahmad2-Jan-04 1:37 
    GeneralConnect to SMTP Pinmembertaualex4-Nov-03 2:30 
    GeneralFree Firewall With Source Code Pinmemberxiamy3-Nov-03 6:52 
    GeneralRe: Free Firewall With Source Code PinmemberEd K11-Feb-04 5:20 
    GeneralRe: Free Firewall With Source Code Pinmemberjproffer20-Jun-04 6:50 
    Generalwan miniport driver Pinmemberdrogoin22-Oct-03 13:46 
    GeneralHijacking UDP packets and getting through a firewall PinsussKieran7726-Mar-03 4:51 
    GeneralRe: Hijacking UDP packets and getting through a firewall PinsussLorca6-Aug-03 21:28 
    GeneralRe: Hijacking UDP packets and getting through a firewall Pinmemberevilnoodle22-Mar-06 23:37 
    GeneralRe: Hijacking UDP packets and getting through a firewall PinmemberMMs_xH26-Jun-04 21:00 
    Generalproxy authorization problem PinmemberManjit17-Feb-03 23:21 
    GeneralNo response from proxy Pinmembergeecka22-Jan-03 18:34 
    GeneralNo response PinmemberRishik200315-Nov-03 6:11 
    GeneralRe: No response PinmemberJustin Deltener19-Nov-03 12:11 
    GeneralRe: No response PinsussAnonymous20-Nov-03 21:37 
    GeneralSMTP through a proxy PinmemberRishikus200320-Nov-03 22:07 
    GeneralRe: SMTP through a proxy PinmemberJustin Deltener21-Nov-03 2:42 
    GeneralRe(2): SMTP through a proxy PinmemberRishikus200323-Nov-03 1:16 
    GeneralHTTP Tunneling question PinmemberWally_wu21-Jan-03 21:57 
    GeneralRe: HTTP Tunneling question PinmemberRishikus200323-Nov-03 1:27 
    QuestionWhat if Destination-Adress is another proxy ??? PinmemberAgent_White10-Jan-03 9:58 
    AnswerRe: What if Destination-Adress is another proxy ??? Pinmemberfriedrichfischer22-Feb-04 3:33 
    GeneralTunnel Implementation PinmemberMars_John26-Dec-02 0:03 
    GeneralRe: Tunnel Implementation Pinsusshttp newbie17-May-03 5:39 
    GeneralPeer-to-peer Firewalled PinsussMaff18-Nov-02 10:08 
    Questionwhat does it mean? PinsussAnonymous22-Oct-02 18:49 
    Questioncan i know how long i spend at connecting to internet through a proxy? Pinmemberleon.li22-Oct-02 18:14 
    Generalchat2 Pinsussevgeni11-Oct-02 3:37 
    Generalfree my port !!! Pinsuss_Vince_30-Sep-02 14:31 
    Generalchat over proxy Pinmembermohamad22-Sep-02 7:52 
    GeneralTunnel failed Pinmembermeta19-Jun-02 22:15 
    GeneralRe: Tunnel failed Pinsussteste28-Sep-02 12:18 
    Questionhow to write firewall? Pinmemberrama surendra babu19-Jun-02 5:40 
    AnswerRe: how to write firewall? PinsussAnonymous12-Aug-02 9:18 
    GeneralGo and test this great proxy/tunel PinmemberAnonymous17-Jun-02 6:16 
    GeneralWinVNC PinmemberAnonymous28-May-02 2:14 
    GeneralRe: WinVNC Pinsussconcise28-Jan-03 8:18 
    GeneralProblem in Source Safe Window Pinmemberkoorosh13-Apr-02 20:39 
    GeneralRe: Problem in Source Safe Window PinmemberAnonymous14-Jun-02 20:20 
    GeneralAnonymity PinmemberRubikz11-Dec-01 12:23 
    GeneralSomeone! PinmemberBoggan11-Oct-01 9:32 
    Generalasdf PinmemberAnonymous8-Jun-01 5:59 
    Generaltunnel Pinmembertkt3-Jun-01 2:14 
    GeneralRe: tunnel Pinmembershekhar5-Jun-01 16:49 
    GeneralRe: tunnel PinmemberCyberCying4-Jun-02 10:20 
    GeneralRealAudio PinmemberAnonymous16-May-01 6:09 
    GeneralProblems with MS Proxy PinmemberFil Mackay19-Mar-01 14:27 
    GeneralNTLM authentication with http-tunneling PinmemberAnonymous13-Dec-00 20:28 
    GeneralRe: NTLM authentication with http-tunneling Pinmemberhendy6-Sep-01 21:15 
    QuestionHow to use Satellite Pinmembershomeet24-Nov-00 3:08 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

    | Advertise | Privacy | Terms of Use | Mobile
    Web03 | 2.8.150414.1 | Last Updated 15 Jun 2000
    Article Copyright 2000 by Alex Turc
    Everything else Copyright © CodeProject, 1999-2015
    Layout: fixed | fluid