Skip to content

Commit

Permalink
code refactoring and optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Feb 2, 2025
1 parent f65bcd5 commit 0f94ec0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 21 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ For ESP8266 device user, you should read the [Memory Options for ESP8266](#memor

Please make sure that the `Arduino IDE's Board Manager URL` is up to date before you update your device's `platform Core SDK`. Any issue due to using out dated `platform Core SDK` is your own risk and does not support by library.

In case the library compile status showed here is passing and your code compilation is error, you should check your libary installation, `platform Core SDK` installation and the library usage. You cannot install library in the cloud storage virtual folder or sandbox e.g. `Microsoft's OneDrive`.
> [!NOTE]
> In the case that the library compilation status shows here is passing and your code compilation is error, you should check your libary installation, `platform Core SDK` installation and the library usage. You cannot install library in the cloud storage virtual folder or sandbox e.g. `Microsoft's OneDrive`.
If you are using `Arduino® MKR 1000 WIFI`, please make sure you have already done the following steps.
- Add the `Realtime Database host root certificate` to the board firmware.
Expand Down Expand Up @@ -1061,7 +1062,7 @@ ServiceAuth::ServiceAuth(<timestamp>, <file_config_data>, <expire>)
The auth token need to be re-created instead of refreshing.
The `CustomAuth` and `ServiceAuth` classes required the JWT token processor which is done via the function `firebase::JWTClass::loop(<auth_data_t*>)` which accepts the pointer to the `auth_data_t` from the `FirebaseApp::getAuth()`.
The `CustomAuth` and `ServiceAuth` classes required the JWT token processor which is done via the function `firebase_ns::JWTClass::loop(<auth_data_t*>)` which accepts the pointer to the `auth_data_t` from the `FirebaseApp::getAuth()`.
The examples in this library, the static object of `JWTClass` called `JWT` will be used to save the stack memory usage and it is not thread safe when using in multi-threaded operations (`multi-FirebaseApp`) because of sharing internal `jwt_token_data_t`.
Expand Down
4 changes: 2 additions & 2 deletions src/core/AsyncClient/RequestHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ struct req_handler
}

void addNewLine() { val[reqns::header] += "\r\n"; }
void addHostHeader(const String &host) { sut.printTo(val[reqns::header], 100, "Host: %s\r\n", host.c_str()); }
void addHostHeader(const String &host) { sut.printTo(val[reqns::header], host.length(), "Host: %s\r\n", host.c_str()); }
void addConnectionHeader(bool keepAlive) { sut.printTo(val[reqns::header], 50, "Connection: %s\r\n", keepAlive ? "keep-alive" : "close"); }
void addContentType(const String &type) { sut.printTo(val[reqns::header], 100, "Content-Type: %s\r\n", type.c_str()); }
void addContentType(const String &type) { sut.printTo(val[reqns::header], type.length(), "Content-Type: %s\r\n", type.c_str()); }
void setContentLengthFinal(size_t len) { sut.printTo(val[reqns::header], 30, "Content-Length: %d\r\n\r\n", (int)len); }
void addRequestHeader(reqns::http_request_method method, const String &path, const String &extras)
{
Expand Down
19 changes: 2 additions & 17 deletions src/core/FirebaseApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,6 @@ namespace firebase_ns
}
}

void addGAPIsHost(String &str, PGM_P sub)
{
str += sub;
if (str[str.length() - 1] != '.')
str += ".";
str += FPSTR("googleapis.com");
}

void addContentTypeHeader(String &header, PGM_P v)
{
header += FPSTR("Content-Type: ");
header += v;
header += FPSTR("\r\n");
}

void createSlot(AsyncClientClass *aClient, slot_options_t &soption)
{
if (aClient)
Expand Down Expand Up @@ -269,10 +254,10 @@ namespace firebase_ns

if (sData)
{
addGAPIsHost(host, subdomain.c_str());
sut.printTo(host, subdomain.length(), "%s.googleapis.com", subdomain.c_str());
newRequestBase(aClient, sData, host, extras, "", reqns::http_post, soption, uid);

addContentTypeHeader(sData->request.val[reqns::header], "application/json");
sData->request.addContentType("application/json");
sData->request.setContentLengthFinal(sData->request.val[reqns::payload].length());
req_timer.feed(FIREBASE_TCP_READ_TIMEOUT_SEC);
slot = slotCountBase(aClient) - 1;
Expand Down

0 comments on commit 0f94ec0

Please sign in to comment.