Skip to content

redirect location gets cleared in setURL(const String& url) function of ESP8266HTTPClient.cpp #6778

New issue

Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “No Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? No Sign in to your account

Closed
Suraj151 opened this issue Nov 15, 2019 · 2 comments · Fixed by #6786
Closed

Comments

@Suraj151
Copy link

i updated to latest release 2.6.0 before my last ota update to devices and now devices are not updating as they do before. i go through debug process where i found subjected issue.

below line return false for redirects in ota update

return beginInternal(url, nullptr);

so i did serial debug at

bool HTTPClient::setURL(const String& url)
{
    // if the new location is only a path then only update the URI
    if (url && url[0] == '/') {
        _uri = url;
        clear();
        return true;
    }

    if (!url.startsWith(_protocol + ':')) {
        DEBUG_HTTPCLIENT("[HTTP-Client][setURL] new URL not the same protocol, expected '%s', URL: '%s'\n", _protocol.c_str(), url.c_str());
        return false;
    }
    // disconnect but preserve _client
    Serial.printf("check url1: %s\n", url.c_str());
    disconnect(true);
    Serial.printf("check url2: %s\n", url.c_str());
    clear();
    Serial.printf("check url3: %s\n", url.c_str());
    return beginInternal(url, nullptr);
}

and at


bool HTTPClient::beginInternal(const String& __url, const char* expectedProtocol)
{
    String url(__url);

    DEBUG_HTTPCLIENT("[HTTP-Client][begin] url: %s\n", url.c_str());
    clear();
    Serial.printf("check url4: %s\n", url.c_str());
    // check for : (http: or https:
    int index = url.indexOf(':');
    if(index < 0) {
        DEBUG_HTTPCLIENT("[HTTP-Client][begin] failed to parse protocol\n");
        return false;
    }

where i found serial debug output as

check url4: http://something
check url1: http://something
check url2: http://something
check url3: 
check url4: 

and resulted that clear() function clears the location url before pass it to beginInterval function.
don't know much why it is cleared before passing, since beginInterval function calls clear at beginning.
i get it done by commenting clear().

@d-a-v
Copy link
Collaborator

d-a-v commented Nov 15, 2019

@liebman can you please have a look to this issue ?
https://github.com/esp8266/Arduino/blame/master/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp#L554

@liebman
Copy link
Contributor

liebman commented Nov 15, 2019

OK - this is because the parameter to setURLwas changed to to a const String& in #6571. And given that beginInternal both forces a local copy of the url and calls clear I'll put a PR together that removes the clear just before beginInternal from setURL.

No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants