HTTPS on Linux

Dec 9, 2013 at 6:53 AM
Hi All,

I'm using Casablanca 1.3 in a Linux SUSE Enterprise (11.2) Environment. I was trying to attempt a GET operation using HTTPS on google.com, but the program failed, without a proffered error code.
terminate called after throwing an instance of 'web::http::http_exception'
  what():  Error code in handle_handshake is
Aborted
I was stepping through the code, and the error is caused inside the "ppls::task::wait()" method. The code snippet I've used is below.
pplx::task<void> HTTPStreamingAsync()
{
    http_client client(U("https://www.google.com"));

    // Make the request and asynchronously process the response.
    return client.request(methods::GET).then([](http_response response)
    {
        // Print the status code.
        std::wostringstream ss;
        ss << U("Server returned returned status code ") << response.status_code() << U('.') << std::endl;
        std::wcout << ss.str();

        // In this example, we print the length of the response to the console.
        ss.str(std::wstring());
        ss << U("Content length is ") << response.headers().content_length() << U(" bytes.") << std::endl;
        ss << U("Content is ") <<  response.to_string().c_str()  << endl;
        std::wcout << ss.str();
    });

}
I copied most of this code from one of the examples for the Casablanca SDK.
Should I have changed anything in order to get HTTPS to work ? The only change I made was to replace "HTTP" with "HTTPS" in the client URL.

One more thing - I was running this on a corporate network, which very probably has proxies configured internally. Could this cause any issues?

Please advise.
Let me know if any more information is needed.
Dec 9, 2013 at 9:54 PM
Hi prashanthravoor,

you can try two things:

First, make sure that your program works fine without SSL i.e. replacing https with http in your URL.

Second, I wasn't able to reproduce the problem, but I am suspecting that I might be caused by not waiting for the task from HTTPStreamingAsync() to be finished and exiting the program prematurely? Are you waiting for this task?

And, are you always getting the same error?

Oggy!
Dec 10, 2013 at 3:33 AM
Hi Oggy,

Thanks for the quick reply.

I have tried the same program in HTTP, and the server does return a response, so to me, it seemed like there wasn't anything wrong with the program itself (apart from the fact that it isn't working).
I am calling wait() on HTTPStreamingAsync() from my main function, so that's not the problem either.

And yes, its the same error each time! :-(

The funny thing is, I have tried this very same code on Windows - it works without a hitch.

That was why I was wondering if there was anything extra that needed to be done on Linux.
Dec 10, 2013 at 4:05 AM
After enclosing the call to the function in a try-catch block, this was the output:
In an Exception:
Error Code: generic:336134278
Error Phrase: Error code in handle_handshake is
The main function:
int main()
{
        try{
                HTTPStreamingAsync().wait();
        }
        catch(http_exception e)
        {
                wcout << "In an Exception: " << endl;
                wcout << "Error Code: " << e.error_code() << endl << "Error Phrase: " << e.what() << endl;
                return -1;
        }
        return 0;
}
Dec 10, 2013 at 7:00 PM
We officially support Ubuntu only, but the library should work with other distributions as well.
You can try your code with the latest Casablanca 1.4 which will be released shortly, most likely today.
Dec 11, 2013 at 3:57 AM
Thanks Oggy, I will try that.
One last thing - Will the new release (1.4) contain support for proxies on Linux / Ubuntu?
Dec 17, 2013 at 6:10 PM
Unfortunately no. We will have them in future.
Mar 14, 2014 at 12:31 AM
Edited Mar 14, 2014 at 12:31 AM
Did you find a resolution?

I have a program that hits many different URLS I manage (mixed http and https) and they all are working. I added a new website I manage that is https, and I am getting the very same issue you are getting. No idea why. The others still work fine.

prashanthravoor wrote:
After enclosing the call to the function in a try-catch block, this was the output:
In an Exception:
Error Code: generic:336134278
Error Phrase: Error code in handle_handshake is
The main function:
int main()
{
        try{
                HTTPStreamingAsync().wait();
        }
        catch(http_exception e)
        {
                wcout << "In an Exception: " << endl;
                wcout << "Error Code: " << e.error_code() << endl << "Error Phrase: " << e.what() << endl;
                return -1;
        }
        return 0;
}
Mar 14, 2014 at 9:37 AM
I have not resolved it, but look at line 398 of:

Release/src/http/client/http_linux.cpp

Not exactly my strength to figure out why this is doing this...

Ideas?
Coordinator
Mar 15, 2014 at 12:53 AM
Hi,

Some additional ideas for thought here. First I think there is something going on with certificates here. Doing a quick search for the error code seems to indicate issues around certificates. I don't know if it will help much, but you can try checking what the message on the std::error_code is in the http_exception. e.error_code().message(). If that doesn't give anything perhaps try checking what the message is in the 'ec' boost::system::error_code variable in the function handle_handleshake in http_linux.cpp.

In the future I agree there is work for us to do to clean up our error reporting/converting here from Boost error_code to std::error_code.

loquitusofborg - specifically what do you mean about the code around 398 in http_linux.cpp?

Thanks,
Steve
Mar 15, 2014 at 1:04 AM
Hi Steve.

I was referring to the file http_linux.cpp in the Casablanca source code -- namely that I suspect this exception is thrown on line 398 of that file. Not a big deal but I grepped recursively through the source to find this in case someone else already had not.

This is on line 398 of my copy, anyways. I did update from git yesterday and there were no updates.

So I have been using the library to talk to a bunch of websites, most of which work. About 15% do not. Could it be they have an expired https certificate or the like and this relates to the bug here?

Thanks for the feedback. Sort of stuck here since I am not really qualified to resolve it. Can you suggest a fix, even if it is not elegant?
Coordinator
Mar 15, 2014 at 1:07 AM
Hi loquitusofborg,

Yes that is absolutely where the error is originating, now the question is why is Boost giving us an error here. What OS are you running on? We only do our testing on Ubuntu and prashanthravoor originally reported the issue on SUSE so we haven't been able to reproduce.

Could you give me some examples of public websites where it fails so we can try to reproduce? Without being able to reproduce on my end it is quite hard to dig deeper.

Thanks,
Steve
Mar 15, 2014 at 1:11 AM
Hi Steve.

I am running on Ubuntu 13.10 64 bit.

I can give you the following two URL's (publicly accessible) that seem to have this issue:

https://crypto-trade.com/api/1/depth/btc_usd
https://www.therocktrading.com/api/orderbook/BTCUSD

Let me know if you are able to reproduce -- information and/or a solution, however in-elegant, would be real appreciated!

Thanks.