Eps32 WiFiClientSecure download file

Hello. I try to download binary file and write it to SD card. My code:

	 WiFiClientSecure clientUpd;
	  clientUpd.setInsecure();
	  
	 
	 if (!clientUpd.connect("maketest.it", 443))
    Serial.println("Connection failed!");
  else {
    Serial.println("Connected to server!");
    clientUpd.println("GET /file.bin HTTP/1.1");
    clientUpd.println("Host: maketest.it");
    clientUpd.println("Connection: close");
    clientUpd.println();
	
	while (clientUpd.available() == 0);

ext::File newF;

newF = SD.open("tmp/test.bin", FILE_WRITE);


while (clientUpd.connected()) {
      String line = clientUpd.readStringUntil('\n');
      Serial.println(line);
      if (line == "\r") {
        Serial.println("headers received");
        break;
      }
    }


      while (clientUpd.available()) {
         
		 byte c = clientUpd.read();
        
		if (newF) {
			newF.write(c);
		}
		
      }
	  
	  newF.close();

    clientUpd.stop();
    Serial.println("Finished read bytes"); 
	
  }

It's start downloading and saved to SD-card, but it's download only 16kb (file over 2mb).

Can you what is trouble and how to download all file? Thanks!!

just a thought

if it's a binary file, you should not try to read it as a text file

there might just not be any '\n' or just by chance in the file and your String will just grow huge and possibly crash your arduino

allocate a buffer, say 512 bytes if your Arduino has lots of SRAM
fill in that buffer using the readBytes() function (check how many you get)
write the buffer to the SD file (using the count of bytes you read)

stop when there is no more bytes to get

String line = clientUpd.readStringUntil('\n');

At this like I read headers

 byte c = clientUpd.read();

hear I read binary data

Headers end with an empty line not when the client is disconnected