Browse Source

fix: HEAD 404 skip_body

ithewei 4 years ago
parent
commit
138a0f72c6
2 changed files with 5 additions and 1 deletions
  1. 4 0
      examples/wget.cpp
  2. 1 1
      http/Http1Parser.cpp

+ 4 - 0
examples/wget.cpp

@@ -21,6 +21,10 @@ static int wget(const char* url, const char* filepath) {
         return -1;
     }
     printd("%s", resp->Dump(true, false).c_str());
+    if (resp->status_code == HTTP_STATUS_NOT_FOUND) {
+        fprintf(stderr, "404 Not Found\n");
+        return -1;
+    }
 
     bool use_range = false;
     int range_bytes = 1 << 20; // 1M

+ 1 - 1
http/Http1Parser.cpp

@@ -110,7 +110,7 @@ int on_headers_complete(http_parser* parser) {
         HttpResponse* res = (HttpResponse*)hp->parsed;
         res->status_code = (http_status)parser->status_code;
         // response to HEAD
-        if (res->status_code == 200 && hp->flags & F_SKIPBODY) {
+        if (hp->flags & F_SKIPBODY) {
             skip_body = true;
         }
     }