+using namespace simgear;
+
+class MetarRequest : public HTTP::Request
+{
+public:
+ bool complete;
+ bool failed;
+ string metarData;
+ bool fromProxy;
+
+ MetarRequest(const std::string& stationId) :
+ HTTP::Request("http://weather.noaa.gov/pub/data/observations/metar/stations/" + stationId + ".TXT"),
+ complete(false),
+ failed(false)
+ {
+ fromProxy = false;
+ }
+
+protected:
+
+ virtual void responseHeader(const string& key, const string& value)
+ {
+ if (key == "x-metarproxy") {
+ fromProxy = true;
+ }
+ }
+
+ virtual void gotBodyData(const char* s, int n)
+ {
+ metarData += string(s, n);
+ }
+
+ virtual void responseComplete()
+ {
+ if (responseCode() == 200) {
+ complete = true;
+ } else {
+ SG_LOG(SG_ENVIRONMENT, SG_WARN, "metar download failed:" << url() << ": reason:" << responseReason());
+ failed = true;
+ }
+ }
+};