ofxSimpleHttp on RPI returns invalid Poco/Net/HttpResponse codes


I have built an App that downloads media from the cloud, and it runs perfectly on Linux x86 and Mac OS X, but when compiled on Raspberry Pi 2 (RPI2) I have found that the Poco/Net/HttpResponse return code is an integer outside of the HTTPStatus enum range of values and seems completely random.

I am using the ofxSimpleHttp addon, and fixed a certain typo bug in its source code to get it to compile on Linux:

Error in line 13 of ofxSimpleHttp.cpp of ofxSimpleHttp addon:

#include "poco/Net/HTTPStreamFactory.h"

should be:

#include “Poco/Net/HTTPStreamFactory.h"

The HTTPStatus invalid enum bug appears at line 723 in ofxSimpleHttp.cpp at this code:

resp->status = res.getStatus();

The status is completely random.

If you add this code at that line in place of line 723:

int rstatus = 0;
            ofLog(OF_LOG_NOTICE, "res.getStatus(): "+ofToString(res.getStatus()) +
                  " : "+ofToString(((unsigned)res.getStatus()) & 0xFFFF) +
                  " "+ofToString(((unsigned)res.getStatus() >> 8) & 0xFFFF) +
                  " "+ofToString(((unsigned)res.getStatus() >> 16) & 0xFFFF) +
                  " "+ofToString(((unsigned)res.getStatus() >> 24) & 0xFFFF));
            switch (res.getStatus()){ //This Switch Statement added by Eric 8-29-2015
            case HTTPResponse::HTTP_CONTINUE:                rstatus = 100; break;
            case HTTPResponse::HTTP_SWITCHING_PROTOCOLS:     rstatus = 101; break;
            case HTTPResponse::HTTP_OK:                      rstatus = 200; break;
            case HTTPResponse::HTTP_CREATED:                 rstatus = 201; break;
            case HTTPResponse::HTTP_ACCEPTED:                rstatus = 202; break;
            case HTTPResponse::HTTP_NONAUTHORITATIVE:        rstatus = 203; break;
            case HTTPResponse::HTTP_NO_CONTENT:              rstatus = 204; break;
            case HTTPResponse::HTTP_RESET_CONTENT:           rstatus = 205; break;
            case HTTPResponse::HTTP_PARTIAL_CONTENT:         rstatus = 206; break;
            case HTTPResponse::HTTP_MULTIPLE_CHOICES:        rstatus = 300; break;
            case HTTPResponse::HTTP_MOVED_PERMANENTLY:       rstatus = 301; break;
            case HTTPResponse::HTTP_FOUND:                   rstatus = 302; break;
            case HTTPResponse::HTTP_SEE_OTHER:               rstatus = 303; break;
            case HTTPResponse::HTTP_NOT_MODIFIED:            rstatus = 304; break;
            case HTTPResponse::HTTP_USEPROXY:                rstatus = 305; break;
                // UNUSED: 306
            case HTTPResponse::HTTP_TEMPORARY_REDIRECT:      rstatus = 307; break;
            case HTTPResponse::HTTP_BAD_REQUEST:             rstatus = 400; break;
            case HTTPResponse::HTTP_UNAUTHORIZED:            rstatus = 401; break;
            case HTTPResponse::HTTP_PAYMENT_REQUIRED:        rstatus = 402; break;
            case HTTPResponse::HTTP_FORBIDDEN:               rstatus = 403; break;
            case HTTPResponse::HTTP_NOT_FOUND:               rstatus = 404; break;
            case HTTPResponse::HTTP_METHOD_NOT_ALLOWED:      rstatus = 405; break;
            case HTTPResponse::HTTP_NOT_ACCEPTABLE:          rstatus = 406; break;
            case HTTPResponse::HTTP_PROXY_AUTHENTICATION_REQUIRED: rstatus = 407; break;
            case HTTPResponse::HTTP_REQUEST_TIMEOUT:         rstatus  = 408; break;
            case HTTPResponse::HTTP_CONFLICT:                rstatus = 409; break;
            case HTTPResponse::HTTP_GONE:                    rstatus = 410; break;
            case HTTPResponse::HTTP_LENGTH_REQUIRED:         rstatus = 411; break;
            case HTTPResponse::HTTP_PRECONDITION_FAILED:     rstatus = 412; break;
            case HTTPResponse::HTTP_REQUESTENTITYTOOLARGE:   rstatus = 413; break;
            case HTTPResponse::HTTP_REQUESTURITOOLONG:       rstatus = 414; break;
            case HTTPResponse::HTTP_UNSUPPORTEDMEDIATYPE:    rstatus = 415; break;
            case HTTPResponse::HTTP_REQUESTED_RANGE_NOT_SATISFIABLE: rstatus = 416; break;
            case HTTPResponse::HTTP_EXPECTATION_FAILED:      rstatus = 417; break;
            case HTTPResponse::HTTP_INTERNAL_SERVER_ERROR:   rstatus = 500; break;
            case HTTPResponse::HTTP_NOT_IMPLEMENTED:         rstatus = 501; break;
            case HTTPResponse::HTTP_BAD_GATEWAY:             rstatus = 502; break;
            case HTTPResponse::HTTP_SERVICE_UNAVAILABLE:     rstatus = 503; break;
            case HTTPResponse::HTTP_GATEWAY_TIMEOUT:         rstatus = 504; break;
            case HTTPResponse::HTTP_VERSION_NOT_SUPPORTED:   rstatus  = 505; break;
            //    default: rstatus = res.getStatus();
            default: rstatus = 222; break;

            resp->status = rstatus;// res.getStatus(); //Eric

rstatus will always be 222, which I have as default when nothing else matches, when run on Raspberry Pi 2.

But on x86 Linux and Mac OS rstatus remains the correct HTTPResponse with this code change.

The actual status returned on Raspberry Pi 2 changes everytime, like a random number. Disregarding the download status, the downloading code works and downloads the media correctly, but to get my App to work I had to make it accept 222 (my default value) as a 200 success, which will be a bug in the event of download failure.

I am using ofxDownloadCentral in ofxSimpleHttp addon, which uses ofxSimpleHttp.cpp, so any of the examples in the addon should show the error on Raspberry Pi 2. I am only using Raspberry Pi 2 as my device.

I believe that the bug is in the Poco/Net/HttpResponse source code outside the ofSimpleHttp addon, and inside the Raspberry Pi 2 codebase of openFrameworks. I don’t believe that the bug is in the Addon because the invalid code comes from code outside the Addon in Poco/Net/HttpResponse.

Has anyone else noticed this bug and found a fix to it. It would be somewhere in the Poco/Net/HttpResponse code for Raspberry Pi 2, so anyone downloading on RPI2 using Poco should come across this bug.

Eric Dunstan

Are you using oF 0.8.4? If so, I’m pretty sure the armv7 distribution has Poco libs compiled that are not fully compatible with raspberry pi 2. Please try the latest master branch or 0.9.0 release candidate.

Hi, bakercp

I was using oF 0.8.4. So I tried using the latest master branch, and I compiled and ran some samples. But when I make a copy of the emptyExample and add the ofxXmlSettings addon to addons.make and then compile with make, it hangs at compiling the ofxXmlSettings. This is version: of_v20151007_linuxarm7l_nightly.

Are problems like this common in the master branch?

Maybe I should try the 0.9.0 release candidate? Where do I get that?

Thank you very much for your help,

Eric Dunstan

the of_v20151007_linuxarm7l_nightly is the right place to start. I haven’t see it hang on ofxXmlSettings before … did it give you any errors? Perhaps it ran out of memory? What is your CPU/GPU memory split?

No error readout, it just died and froze at the point where it was compiling ofxXmlSettings. Neither mouse nor keyboard worked. I had to unplug it. CPU/GPU split has not been changed from default. I tried it twice. I also made a copy of emptyExample without adding that addon and that compiled and ran no problem. I also compiled and ran two examples with no problem: 3D Primitives, and the Video Player.

I also saw the projectGenerator, but when I did make, it failed to compile. I am using Raspbian on RPI2 (ARMv7).