1515//
1616#include " Firebase.h"
1717
18+ // Detect whether stable version of HTTP library is installed instead of
19+ // master branch and patch in missing status and methods.
20+ #ifndef HTTP_CODE_TEMPORARY_REDIRECT
21+ #define HTTP_CODE_TEMPORARY_REDIRECT 307
22+ #define USE_STABLE_HTTPCLIENT_CORE
23+ #endif
24+
1825namespace {
1926const char * kFirebaseFingerprint = " 7A 54 06 9B DC 7A 25 B3 86 8D 66 53 48 2C 0B 96 42 C7 B3 0A" ;
2027const uint16_t kFirebasePort = 443 ;
@@ -74,15 +81,15 @@ FirebaseCall::FirebaseCall(const String& host, const String& auth,
7481 bool followRedirect = false ;
7582 if (method == " STREAM" ) {
7683 method = " GET" ;
77- http_->addHeader (" Accept" , " text/event-stream" );
84+ http_->addHeader (" Accept" , " text/event-stream" );
7885 followRedirect = true ;
7986 }
8087
8188 if (followRedirect) {
8289 const char * headers[] = {" Location" };
8390 http_->collectHeaders (headers, 1 );
8491 }
85-
92+
8693 int status = http_->sendRequest (method, (uint8_t *)data.c_str (), data.length ());
8794
8895 // TODO: Add a max redirect check
@@ -98,7 +105,11 @@ FirebaseCall::FirebaseCall(const String& host, const String& auth,
98105 }
99106
100107 if (status != 200 ) {
108+ #ifdef USE_STABLE_HTTPCLIENT_CORE
109+ error_ = FirebaseError (status, String (method) + " " + url + " : " + status);
110+ #else
101111 error_ = FirebaseError (status, String (method) + " " + url + " : " + HTTPClient::errorToString (status));
112+ #endif
102113 }
103114
104115 // if not streaming.
@@ -112,7 +123,6 @@ FirebaseGet::FirebaseGet(const String& host, const String& auth,
112123 const String& path,
113124 HTTPClient* http)
114125 : FirebaseCall(host, auth, " GET" , path, " " , http) {
115-
116126 if (!error ()) {
117127 // TODO: parse json
118128 json_ = response ();
@@ -121,10 +131,9 @@ FirebaseGet::FirebaseGet(const String& host, const String& auth,
121131
122132// FirebaseSet
123133FirebaseSet::FirebaseSet (const String& host, const String& auth,
124- const String& path, const String& value,
125- HTTPClient* http)
134+ const String& path, const String& value,
135+ HTTPClient* http)
126136 : FirebaseCall(host, auth, " PUT" , path, value, http) {
127-
128137 if (!error ()) {
129138 // TODO: parse json
130139 json_ = response ();
0 commit comments