@@ -70,7 +70,8 @@ class SFCCMockWebDAVServer {
7070 // Add CORS headers
7171 res . setHeader ( 'Access-Control-Allow-Origin' , '*' ) ;
7272 res . setHeader ( 'Access-Control-Allow-Methods' , 'GET, HEAD, OPTIONS, PROPFIND' ) ;
73- res . setHeader ( 'Access-Control-Allow-Headers' , 'Content-Type, Authorization, Depth' ) ;
73+ res . setHeader ( 'Access-Control-Allow-Headers' , 'Content-Type, Authorization, Depth, Range' ) ;
74+ res . setHeader ( 'Access-Control-Expose-Headers' , 'Content-Range, Accept-Ranges' ) ;
7475
7576 if ( this . isDevMode ) {
7677 console . log ( `[${ new Date ( ) . toISOString ( ) } ] ${ req . method } ${ req . url } ` ) ;
@@ -128,9 +129,17 @@ class SFCCMockWebDAVServer {
128129 return ;
129130 }
130131
132+ // Handle range requests for partial content
133+ const rangeHeader = req . headers . range ;
134+ if ( rangeHeader ) {
135+ return this . handleRangeRequest ( req , res , fsPath , stats ) ;
136+ }
137+
138+ // Normal full file request
131139 res . statusCode = 200 ;
132140 res . setHeader ( 'Content-Type' , 'text/plain' ) ;
133141 res . setHeader ( 'Content-Length' , stats . size ) ;
142+ res . setHeader ( 'Accept-Ranges' , 'bytes' ) ;
134143
135144 const stream = fs . createReadStream ( fsPath ) ;
136145 stream . pipe ( res ) ;
@@ -141,6 +150,57 @@ class SFCCMockWebDAVServer {
141150 }
142151 }
143152
153+ handleRangeRequest ( req , res , fsPath , stats ) {
154+ try {
155+ const rangeHeader = req . headers . range ;
156+ const fileSize = stats . size ;
157+
158+ if ( this . isDevMode ) {
159+ console . log ( `[DEBUG] Range request: ${ rangeHeader } for file ${ fsPath } (size: ${ fileSize } )` ) ;
160+ }
161+
162+ // Parse range header (e.g., "bytes=0-499" or "bytes=500-999")
163+ const rangeMatch = rangeHeader . match ( / b y t e s = ( \d + ) - ( \d * ) / ) ;
164+ if ( ! rangeMatch ) {
165+ res . statusCode = 416 ; // Range Not Satisfiable
166+ res . setHeader ( 'Content-Range' , `bytes */${ fileSize } ` ) ;
167+ res . end ( 'Range Not Satisfiable' ) ;
168+ return ;
169+ }
170+
171+ const start = parseInt ( rangeMatch [ 1 ] , 10 ) ;
172+ const end = rangeMatch [ 2 ] ? parseInt ( rangeMatch [ 2 ] , 10 ) : fileSize - 1 ;
173+
174+ // Validate range
175+ if ( start >= fileSize || end >= fileSize || start > end ) {
176+ res . statusCode = 416 ; // Range Not Satisfiable
177+ res . setHeader ( 'Content-Range' , `bytes */${ fileSize } ` ) ;
178+ res . end ( 'Range Not Satisfiable' ) ;
179+ return ;
180+ }
181+
182+ const contentLength = end - start + 1 ;
183+
184+ if ( this . isDevMode ) {
185+ console . log ( `[DEBUG] Range: ${ start } -${ end } , Content-Length: ${ contentLength } ` ) ;
186+ }
187+
188+ // Send partial content response
189+ res . statusCode = 206 ; // Partial Content
190+ res . setHeader ( 'Content-Type' , 'text/plain' ) ;
191+ res . setHeader ( 'Content-Length' , contentLength ) ;
192+ res . setHeader ( 'Content-Range' , `bytes ${ start } -${ end } /${ fileSize } ` ) ;
193+ res . setHeader ( 'Accept-Ranges' , 'bytes' ) ;
194+
195+ const stream = fs . createReadStream ( fsPath , { start, end } ) ;
196+ stream . pipe ( res ) ;
197+ } catch ( error ) {
198+ console . error ( 'Error handling range request:' , error ) ;
199+ res . statusCode = 500 ;
200+ res . end ( 'Internal Server Error' ) ;
201+ }
202+ }
203+
144204 handlePropfind ( req , res , fsPath , urlPath ) {
145205 try {
146206 if ( this . isDevMode ) {
0 commit comments