Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 424e1bf

Browse files
committed
Merge pull request #63 from gguuss/compat
Add support for stable branch of HTTP client library
2 parents fdf18aa + f3dcace commit 424e1bf

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

Firebase.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
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_ESP_ARDUINO_CORE_2_0_0
23+
#endif
24+
1825
namespace {
1926
const char* kFirebaseFingerprint = "7A 54 06 9B DC 7A 25 B3 86 8D 66 53 48 2C 0B 96 42 C7 B3 0A";
2027
const 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_ESP_ARDUINO_CORE_2_0_0
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
123133
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)
126136
: FirebaseCall(host, auth, "PUT", path, value, http) {
127-
128137
if (!error()) {
129138
// TODO: parse json
130139
json_ = response();

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ This sample shows how to call [Firebase](https://www.firebase.com/) from the [ES
77
## Requirements
88

99
- 1 [ESP8266 Arduino board](https://www.adafruit.com/products/2821).
10-
- [Arduino 1.6.x](https://www.arduino.cc/en/Main/Software)
11-
- ESP8266 Arduino board definition [(master branch)](https://github.com/esp8266/Arduino#using-git-version-)
10+
- [Arduino 1.6.7](https://www.arduino.cc/en/Main/Software)
11+
- [ESP8266 Arduino board definition](https://github.com/esp8266/Arduino#installing-with-boards-manager)
1212

1313
## Setup
1414

0 commit comments

Comments
 (0)