This repository was archived by the owner on Mar 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 492
FirebaseHttpClient: add forceReuse #260
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,12 +15,44 @@ | |
#define USE_ESP_ARDUINO_CORE_2_0_0 | ||
#endif | ||
|
||
// Firebase now returns `Connection: close` after REST streaming redirection. | ||
// | ||
// Override the built-in ESP8266HTTPClient to *not* close the | ||
// connection if forceReuse it set to `true`. | ||
class ForceReuseHTTPClient : public HTTPClient { | ||
public: | ||
void end() { | ||
if(connected()) { | ||
if(_tcp->available() > 0) { | ||
DEBUG_HTTPCLIENT("[HTTP-Client][end] still data in buffer (%d), clean up.\n", _tcp->available()); | ||
while(_tcp->available() > 0) { | ||
_tcp->read(); | ||
} | ||
} | ||
if(_reuse && (_canReuse || _forceReuse)) { | ||
DEBUG_HTTPCLIENT("[HTTP-Client][end] tcp keep open for reuse\n"); | ||
} else { | ||
DEBUG_HTTPCLIENT("[HTTP-Client][end] tcp stop\n"); | ||
_tcp->stop(); | ||
} | ||
} else { | ||
DEBUG_HTTPCLIENT("[HTTP-Client][end] tcp is closed\n"); | ||
} | ||
} | ||
void forceReuse(bool forceReuse) { | ||
_forceReuse = forceReuse; | ||
} | ||
protected: | ||
bool _forceReuse = false; | ||
}; | ||
|
||
class FirebaseHttpClientEsp8266 : public FirebaseHttpClient { | ||
public: | ||
FirebaseHttpClientEsp8266() {} | ||
|
||
void setReuseConnection(bool reuse) override { | ||
void setReuseConnection(bool reuse) override { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. trailing space There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
http_.setReuse(reuse); | ||
http_.forceReuse(reuse); | ||
} | ||
|
||
void begin(const std::string& url) override { | ||
|
@@ -64,7 +96,7 @@ class FirebaseHttpClientEsp8266 : public FirebaseHttpClient { | |
} | ||
|
||
private: | ||
HTTPClient http_; | ||
ForceReuseHTTPClient http_; | ||
}; | ||
|
||
FirebaseHttpClient* FirebaseHttpClient::create() { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another possibility is to call HTTPClient::end here with _canReuse set to true before it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that better only because it deviates less from the base so as the base changes we can merge with impunity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done