@@ -74,40 +74,46 @@ esp_err_t ESP3DHttpService::webdav_get_handler(httpd_req_t *req) {
7474 // Add Content-Length header
7575 httpd_resp_set_hdr (req, " Content-Length" ,
7676 std::to_string (file_size).c_str ());
77- }
78- // open file
79- FILE *fd = globalFs.open (uri.c_str (), " r" );
80- if (fd) {
81- size_t chunksize;
82- size_t total_send = 0 ;
83- // send file
84- do {
85- // Read data block from the file
86- chunksize = fread (_chunk, 1 , CHUNK_BUFFER_SIZE, fd);
87- total_send += chunksize;
88- if (chunksize > 0 ) {
89- // Send the HTTP data block
90- if (httpd_resp_send_chunk (req, _chunk, chunksize) != ESP_OK) {
91- esp3d_log_e (" File sending failed!" );
92- chunksize = 0 ;
93- response_code = 500 ;
94- response_msg = " Failed to send file" ;
77+
78+ // open file
79+ FILE *fd = globalFs.open (uri.c_str (), " r" );
80+ if (fd) {
81+ size_t chunksize;
82+ size_t total_send = 0 ;
83+ // send file
84+ do {
85+ // Read data block from the file
86+ chunksize = fread (_chunk, 1 , CHUNK_BUFFER_SIZE, fd);
87+ total_send += chunksize;
88+ if (chunksize > 0 ) {
89+ // Send the HTTP data block
90+ if (httpd_resp_send_chunk (req, _chunk, chunksize) != ESP_OK) {
91+ esp3d_log_e (" File sending failed!" );
92+ chunksize = 0 ;
93+ response_code = 500 ;
94+ response_msg = " Failed to send file" ;
95+ }
9596 }
97+ } while (chunksize != 0 );
98+ // Close the file
99+ fclose (fd);
100+ httpd_resp_send_chunk (req, NULL , 0 );
101+ // Check if all the file has been sent
102+ if (total_send != file_size) {
103+ esp3d_log_e (" File sending failed: size do not match!" );
104+ response_code = 500 ;
105+ response_msg = " File sending failed: size do not match!" ;
96106 }
97- } while (chunksize != 0 );
98- // Close the file
99- fclose (fd);
100- httpd_resp_send_chunk (req, NULL , 0 );
101- // Check if all the file has been sent
102- if (total_send != file_size) {
103- esp3d_log_e (" File sending failed: size do not match!" );
107+ } else {
108+ esp3d_log_e (" Failed to open file" );
104109 response_code = 500 ;
105- response_msg = " File sending failed: size do not match! " ;
110+ response_msg = " Failed to open file " ;
106111 }
107112 } else {
108- esp3d_log_e (" Failed to open file" );
109- response_code = 500 ;
110- response_msg = " Failed to open file" ;
113+ // is directory
114+ esp3d_log_e (" This is not a file" );
115+ response_code = 405 ;
116+ response_msg = " This is not a file" ;
111117 }
112118 }
113119 // release access
0 commit comments