如何https `GET`从Azure存储CDN获取文件的新副本?

cbeh67ev  于 2023-05-07  发布在  其他
关注(0)|答案(1)|浏览(129)

基本上,我想GET https在开发过程中的Azure存储CDN的新鲜副本。但我不想等待20小时的CDN再水合。
我尝试添加头文件Cache-control: no-cache, no-store, must-revalidate,但没有成功。
我的文件有Cache-control: no-cache, no-store, must-revalidate属性如下:

奇怪的是,当我从Chrome或Safari从我的MacBook Pro的GET,我得到最新的(新鲜)版本,而当我做的GET从我的ESP32为基础的自定义PCB通过相同的SSID WiFi我得到旧版本。
代码如下:

/// @brief Writes the GET on [path] and write mandatory constant headers
/// @param host The host name
/// @param path The path of he document to get
static void httpsGetWriteMandatoryHeaders(char const *hostname, char const * path) {
    client.printf("GET %s HTTP/1.1", path);             client.println();
    client.printf("Host: %s", hostname);                client.println();

    client.printf("Accept-encoding: gzip, deflate");    client.println();
    client.printf("Cache-control: no-cache, no-store, must-revalidate"); client.println();
    client.print ("Accept-encoding: gzip, deflate");    client.println();
}

bool NanoWifi :: httpsGet(
    char const *hostname, char const *path, 
    byte *buffer, size_t bufferCapacity, 
    size_t &bodyLength, bool &bufferOverflows,
    void (*downloadChunkCallback)(byte * buffer, size_t bufferReadCount, size_t contentLength),
    bool verbose
    ) {

    log("Time is: %d %d %d %02d:%02d:%02d", day(), month(), year(), hour(), minute(), second());

    char const * subModule = "httpsGet: ";
    
    if (verbose) log("%sbegin %s%s…",subModule, hostname, path);
    
    // === if you get a connection, report back via serial:
    if (!client.connect(hostname, 443)) {
        // if you didn't get a connection to the server:
        error("%sconnection failed", subModule);
        return false;
    }

    unsigned chunkIndex = 0;

    success("%sConnected!",subModule);

    // Make a HTTP request:
    httpsGetWriteMandatoryHeaders(hostname, path);

    client.printf("Range: bytes=%d-%d", chunkIndex*bufferCapacity, (chunkIndex+1)*bufferCapacity);              client.println();
    client.println();

// etc.

请注意,我使用Range:头来获取小块,因为我没有足够的内存来获取更大的固件文件块。但我不认为这对我该高速缓存问题有什么影响。
你知道我应该怎么做GET吗?

qyswt5oh

qyswt5oh1#

我有一个解决方案,我真的不明白,所以会很高兴有人给了一个理由。
通过使用br设置Accept-Encoding头可以工作。我的代码变成:

/// @brief Writes the GET on [path] and write mandatory constant headers
/// @param host The host name
/// @param path The path of he document to get
static void httpsGetWriteMandatoryHeaders(char const *hostname, char const * path) {
    client.printf("GET %s HTTP/1.1", path);             client.println();
    client.printf("Host: %s", hostname);                client.println();

    client.print ("Cache-Control: no-cache, no-store, must-revalidate"); client.println();
    client.print ("Accept-Encoding: gzip, deflate, br"); client.println();
}

还请注意,我的file属性现在设置回(虽然似乎没有任何效果):

CacheControl: max-age=0

我也用curl表示:如果没有br,则不工作;这是可行的:

curl -H "Accept-Encoding: gzip, deflate, br" <url> --output test.bin

但这并不:

curl -H "Accept-Encoding: gzip, deflate" <url> --output test.bin

相关问题