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

Add support for stable branch of HTTP client library #63

Merged
merged 7 commits into from
Feb 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions Firebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
//
#include "Firebase.h"

// Detect whether stable version of HTTP library is installed instead of
// master branch and patch in missing status and methods.
#ifndef HTTP_CODE_TEMPORARY_REDIRECT
#define HTTP_CODE_TEMPORARY_REDIRECT 307
#define USE_ESP_ARDUINO_CORE_2_0_0
#endif

namespace {
const char* kFirebaseFingerprint = "7A 54 06 9B DC 7A 25 B3 86 8D 66 53 48 2C 0B 96 42 C7 B3 0A";
const uint16_t kFirebasePort = 443;
Expand Down Expand Up @@ -74,15 +81,15 @@ FirebaseCall::FirebaseCall(const String& host, const String& auth,
bool followRedirect = false;
if (method == "STREAM") {
method = "GET";
http_->addHeader("Accept", "text/event-stream");
http_->addHeader("Accept", "text/event-stream");
followRedirect = true;
}

if (followRedirect) {
const char* headers[] = {"Location"};
http_->collectHeaders(headers, 1);
}

int status = http_->sendRequest(method, (uint8_t*)data.c_str(), data.length());

// TODO: Add a max redirect check
Expand All @@ -98,7 +105,11 @@ FirebaseCall::FirebaseCall(const String& host, const String& auth,
}

if (status != 200) {
#ifdef USE_ESP_ARDUINO_CORE_2_0_0
error_ = FirebaseError(status, String(method) + " " + url + ": " + status);
#else
error_ = FirebaseError(status, String(method) + " " + url + ": " + HTTPClient::errorToString(status));
#endif
}

// if not streaming.
Expand All @@ -112,7 +123,6 @@ FirebaseGet::FirebaseGet(const String& host, const String& auth,
const String& path,
HTTPClient* http)
: FirebaseCall(host, auth, "GET", path, "", http) {

if (!error()) {
// TODO: parse json
json_ = response();
Expand All @@ -121,10 +131,9 @@ FirebaseGet::FirebaseGet(const String& host, const String& auth,

// FirebaseSet
FirebaseSet::FirebaseSet(const String& host, const String& auth,
const String& path, const String& value,
HTTPClient* http)
const String& path, const String& value,
HTTPClient* http)
: FirebaseCall(host, auth, "PUT", path, value, http) {

if (!error()) {
// TODO: parse json
json_ = response();
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ This sample shows how to call [Firebase](https://www.firebase.com/) from the [ES
## Requirements

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

## Setup

Expand Down