[TIP] Capture HTTP traffic

Olemis Lang olemis at gmail.com
Thu Nov 4 11:51:23 PDT 2010


On Thu, Nov 4, 2010 at 11:03 AM, Alex <alex.lavoro.propio at gmail.com> wrote:
> 2010/11/3 Olemis Lang <olemis at gmail.com>:
>> Probably I didn't understand your original question . If that's the
>> case , please tell so that we can refine the answer .
>
> I am writing the test of a C++ application. I have access the C++
> source code but prefer not to alter it.
>

I c .

> 2010/11/3 Olemis Lang <olemis at gmail.com>:
[...]
>> wsgi_intercept : To intercept HTTP requests
>> twill | mechanize : For high-level HTTP commands (and more ...)
>
> The target to be tested is a C++ application, so  Python tools like
> wsgi_intercept, twill, mechanize do not apply.
>

Unless :

  - you consider Ronny's suggestion and hijack hosts file ...
  - ... or write a C wrapper or DLL, or COM, or SO or ...
     (add anything accessible using C API, ctypes, swig,
     or similar integration techs) and then use C code
     from Py directly (then twill et al. might help).


> 2010/11/3 C. Titus Brown <ctb at msu.edu>:
>> you could write a simple HTTP server of your own, and run it in another
>> thread.  That doesn't help if you need to call remote URLs, though.
>
> It requires a lot of work to mock the HTTP server. Besides, I need
> some reliable mechanism to redirect the HTTP requests issued by the
> test target (C++ application) to 'localhost'.
>

That's exactly what a web proxy is all about !!!
You put in the middle and do whatever you want with HTTP requests !!!
(and here's where Fiddler scripting | plugins might help - but /me not
sure about Python integration ...)

In any case you could also write your own (test) server (like Titus
said ;o) and make it act as a proxy !!! (which will definitely work
with remote URLs if the C app is prepared for using proxies e.g. by
specifying configs) . Then the proxy (i.e. test server) receives the
requests and , instead of forwarding them to the real host it will

  - Assert whatever you need to check
  - Return fake (but valid ?) requests to the target C app .

Hope this helps .

-- 
Regards,

Olemis.

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:



More information about the testing-in-python mailing list