Skip to content

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

Closed
@Suraj151

Description

@Suraj151

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().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions