Changeset 55 in cheroxy for trunk/src/main.cpp


Ignore:
Timestamp:
12/07/12 10:00:01 (11 years ago)
Author:
cheese
Message:

#1 요청 메시지 변조하는 예제로 main 구성

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/main.cpp

    r52 r55  
    99#include <iomanip>
    1010#include <sstream>
     11#include <string>
    1112
    1213#include <stdio.h>
     
    2829#endif
    2930
     31#define PROXY_CONNECTION    "Proxy-Connection"
     32#define CONNECTION          "Connection"
     33
    3034THREAD_FUNCTION_RETURN
    3135THREAD_FUNCTION_CALLING_CONVENTION
     
    3438int ThreadPool (CRXSocket   * aProxySocket,
    3539                const int   aThreadPoolCount);
     40
     41bool    gViewRequest    = true;
     42bool    gViewResponse   = false;
    3643
    3744int main (int argc, char* argv[])
     
    110117    CRXProxy    * aProxy = NULL;
    111118
    112     char        aFilterFileExtension[] = "exe|gif|jpg|png|css|js|ico|swf|";
     119    const char  aFilterFileExtension[] = "exe|gif|jpg|png|css|js|ico|swf|";
    113120
    114121    /*----------------------------------------------------------------*/
     
    140147                                  aFilterFileExtension);
    141148
    142         aResult = aProxy->Forward ();
     149        aResult = aProxy->ReceiveRequest ();
    143150        if (aResult < 0)
    144151        {
     
    146153        }
    147154
    148         if (!aFilter.CheckRequestFilter (CRX_FILTER_REQUEST_FILE_EXTENSION, aRequest))
     155        if (gViewRequest && !aFilter.CheckRequestFilter (CRX_FILTER_REQUEST_FILE_EXTENSION, aRequest))
    149156        {
     157            string aRequestHeader = aRequest.GetHeader ();
     158            aRequestHeader.replace (aRequest.GetHeader ().find (PROXY_CONNECTION), strlen (PROXY_CONNECTION), CONNECTION);
     159            aRequest.SetHeader (aRequestHeader.c_str ());
     160
    150161            CRX_DEBUG_TRACE ("== Request:  \n%s\n", aRequest.GetHeader ().c_str ());
     162        }
     163
     164        aResult = aProxy->SendRequest ();
     165        if (aResult < 0)
     166        {
     167            cout << aProxy->GetErrorMessage () << endl;
     168        }
     169
     170        aResult = aProxy->ReceiveResponse ();
     171        if (aResult < 0)
     172        {
     173            cout << aProxy->GetErrorMessage () << endl;
     174        }
     175
     176        if (gViewResponse && !aFilter.CheckRequestFilter (CRX_FILTER_REQUEST_FILE_EXTENSION, aRequest))
     177        {
    151178            CRX_DEBUG_TRACE ("== Response: \n%s\n", aResponse.GetHeader ().c_str ());
    152179            CRX_DEBUG_TRACE_BIN (aResponse.GetContentBody (),
    153180                                 aResponse.GetContentLength (),
    154181                                 "== Content-Body: \n");
     182        }
     183
     184        aResult = aProxy->SendResponse ();
     185        if (aResult < 0)
     186        {
     187            cout << aProxy->GetErrorMessage () << endl;
    155188        }
    156189
Note: See TracChangeset for help on using the changeset viewer.