I wrote the HTTP client library a long time ago.
To test the HTTP client library, I just wrote a simple test code that started listening on std::thread on some random port on localhost . Then I told the client to make a test request with the host and port parameters, as in your case, pointing to the port that was listening to my stream now. The stream code was programmed to receive a connection, read an HTTP request, save it, and then respond to it using a canned HTTP response.
And how I tested my client library, checking both the actual request sent by the client and how the client handled the complete HTTP response. Later, I developed this unit test code to send various kinds of HTTP errors and incorrect HTTP responses to test and verify how client code handled these situations.
And for a good measure, all this was protected by the alarm() call, so if something got stuck in an infinite loop or so, the whole process would eventually commit suicide.
And how can you check your own code too, too.
Sam varshavchik
source share