15
15
//
16
16
#include " Firebase.h"
17
17
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
+
18
25
namespace {
19
26
const char * kFirebaseFingerprint = " 7A 54 06 9B DC 7A 25 B3 86 8D 66 53 48 2C 0B 96 42 C7 B3 0A" ;
20
27
const uint16_t kFirebasePort = 443 ;
@@ -74,15 +81,15 @@ FirebaseCall::FirebaseCall(const String& host, const String& auth,
74
81
bool followRedirect = false ;
75
82
if (method == " STREAM" ) {
76
83
method = " GET" ;
77
- http_->addHeader (" Accept" , " text/event-stream" );
84
+ http_->addHeader (" Accept" , " text/event-stream" );
78
85
followRedirect = true ;
79
86
}
80
87
81
88
if (followRedirect) {
82
89
const char * headers[] = {" Location" };
83
90
http_->collectHeaders (headers, 1 );
84
91
}
85
-
92
+
86
93
int status = http_->sendRequest (method, (uint8_t *)data.c_str (), data.length ());
87
94
88
95
// TODO: Add a max redirect check
@@ -98,7 +105,11 @@ FirebaseCall::FirebaseCall(const String& host, const String& auth,
98
105
}
99
106
100
107
if (status != 200 ) {
108
+ #ifdef USE_STABLE_HTTPCLIENT_CORE
109
+ error_ = FirebaseError (status, String (method) + " " + url + " : " + status);
110
+ #else
101
111
error_ = FirebaseError (status, String (method) + " " + url + " : " + HTTPClient::errorToString (status));
112
+ #endif
102
113
}
103
114
104
115
// if not streaming.
@@ -112,7 +123,6 @@ FirebaseGet::FirebaseGet(const String& host, const String& auth,
112
123
const String& path,
113
124
HTTPClient* http)
114
125
: FirebaseCall(host, auth, " GET" , path, " " , http) {
115
-
116
126
if (!error ()) {
117
127
// TODO: parse json
118
128
json_ = response ();
@@ -121,10 +131,9 @@ FirebaseGet::FirebaseGet(const String& host, const String& auth,
121
131
122
132
// FirebaseSet
123
133
FirebaseSet::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)
126
136
: FirebaseCall(host, auth, " PUT" , path, value, http) {
127
-
128
137
if (!error ()) {
129
138
// TODO: parse json
130
139
json_ = response ();
0 commit comments