ソースを参照

fix wget Range

ithewei 4 年 前
コミット
b49eff3020
2 ファイル変更5 行追加2 行削除
  1. 3 1
      examples/wget.cpp
  2. 2 1
      http/server/HttpHandler.cpp

+ 3 - 1
examples/wget.cpp

@@ -70,10 +70,12 @@ static int wget(const char* url, const char* filepath) {
         // print progress
         int cur_progress = from * 100 / content_length;
         if (cur_progress > last_progress) {
-            printf("progress: %ld/%ld = %d%%\n", (long)from, (long)content_length, (int)cur_progress);
+            printf("\rprogress: %ld/%ld = %d%%", (long)from, (long)content_length, (int)cur_progress);
+            fflush(stdout);
             last_progress = cur_progress;
         }
     }
+    printf("\n");
     http_client_del(cli);
 
     return 0;

+ 2 - 1
http/server/HttpHandler.cpp

@@ -140,7 +140,8 @@ int HttpHandler::defaultStaticHandler() {
     }
     if (!is_dir || is_index_of) {
         FileCache::OpenParam param;
-        param.need_read = req->method == HTTP_HEAD ? false : true;
+        bool has_range = req->headers.find("Range") != req->headers.end();
+        param.need_read = req->method == HTTP_HEAD || has_range ? false : true;
         param.path = req_path;
         fc = files->Open(filepath.c_str(), &param);
         if (fc == NULL) {