openframeworks/openFrameworks — Issue #837: ofURLFileLoader dosen't set HTTP User-Agent string and there is no way to set it
Author: danomatika
Created: 2011-12-05 21:44:08+00:00
State: open

I made a small example which uses the Wikipedia xml api to make queries which are then parsed by an ofXmlSettings object. The problem is Wikipedia complains there is no User-Agent string and dosen't return any data, while threatening to block by IP.

The fix was as simple as adding this to ofURLFileLoader.cpp line 144:

HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
req.add("User-Agent", "Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405");

It uses the iOS safari user agent string. I think the best fix is to expose the HTTPRequest and HTTPResponse Poco objects so that, like in the ofxHttpUtils, you could add manually the string/value to the request before sending it. I don't think it should be set ti a default within the class. Also, it would be awesome to be able to add data into and pull data out of the requests. This is a great wrapper, especially the threading, I'd just like to have the full req/response control ... perhaps provide a method to add Poco::HttpRequests and recieve Poco::HttpResponses which could be set as references inside the ofxHttpRequest/ofxHttpResponse objects?

On another note, ofURLFileLoader seems like a rather specific name for a regular HTTP action. What's wrong with ofHttpSession etc since I've found it useful for more then just