HTTPClient doesn't respect CNAME TTL
- Dominant language
- C++
- Stars
- 16.7k
- Forks
- 13.1k
- PR merge metrics
- No merged PRs in 30d
Description
### Basic Infos
- [X] This issue complies with the [issue POLICY doc](https://github.com/esp8266/Arduino/blob/master/POLICY.md).
- [X] I have read the documentation at [readthedocs](https://arduino-esp8266.readthedocs.io/en/latest) and the issue is not addressed there.
- [ ] I have tested that the issue is present in current master branch (aka latest git).
- [X] I have searched the issue tracker for a similar issue.
- [x] If there is a stack dump, I have decoded it.
- [X] I have filled out all fields below.
#### Platform
- Hardware: ESP8266
- Core Version: ??? Arduino IDE 2.3.2 2024-02-20T09:54:08669Z ???
- Development Env: Arduino IDE
- Operating System: Debian 11
### Settings in IDE
- Module: Wemos D1 mini (clone)
- Flash Mode: ???
- Flash Size: ???
- lwip Variant: ???
- Reset Method: ???
- Flash Frequency: ???
- CPU Frequency: ???
- Upload Using: Serial
- Upload Speed: 921600
### Problem Description
I am sending web requests to systems which are configured for failover using CNAME records with low TTL values which point to A records with higher values. For example, I have 4 DNS records:
* myproject.example.com CNAME TTL 60 -> node1.example.com (primary)
* myproject.example.com CNAME TTL 60 -> node2.example.com (secondary)
* node1.example.com A TTL 86400 203.0.113.1
* node2.example.com A TTL 86400 198.51.100.2
I am expecting the TTL of both records to be respected. When the CNAME expires a new lookup should be performed.
In practice, the esp8266 library appears to ignore the CNAME TTL and a new lookup is performed only when the underlying A record expires.
### Sketch
```cpp
#include
#include
void setup() {
WiFi.begin("TheSSID", "ThePSK");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print('.');
}
}
void webRequest() {
WiFiClient client;
HTTPClient http;
if (http.begin(client, "http://myproject.example.com/useful_endpoint/")) {
int httpCode = http.GET();
if (httpCode > 0) {
Serial.printf("[HTTPS] GET status code: %d\n", httpCode);
} else {
Serial.printf("[HTTPS] GET failed; status code: %d)\n", httpCode);
}
http.end();
} else {
Serial.print("connection failed");
}
}
void loop() {
delay(5000);
webRequest();
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.