@@ -416,16 +416,19 @@ public static void OutputHttpCode(HttpListenerResponse response, HttpStatusCode
416416 /// <summary>
417417 /// Return a file from Storage over HTTP response.
418418 /// </summary>
419- public static void SendFileOverHTTP ( HttpListenerResponse response , StorageFile strFilePath )
419+ /// <param name="response"><see cref="HttpListenerResponse"/> to send the content over.</param>
420+ /// <param name="strFilePath">The file to send</param>
421+ /// <param name="contentType">The type of file, if empty string, then will use auto detection</param>
422+ public static void SendFileOverHTTP ( HttpListenerResponse response , StorageFile strFilePath , string contentType = "" )
420423 {
421- string ContentType = GetContentTypeFromFileName ( strFilePath . FileType ) ;
422-
424+ contentType = contentType == "" ? GetContentTypeFromFileName ( strFilePath . FileType ) : contentType ;
425+
423426 try
424427 {
425428 IBuffer readBuffer = FileIO . ReadBuffer ( strFilePath ) ;
426429 long fileLength = readBuffer . Length ;
427430
428- response . ContentType = ContentType ;
431+ response . ContentType = contentType ;
429432 response . ContentLength64 = fileLength ;
430433 // Now loops sending all the data.
431434
@@ -459,13 +462,14 @@ public static void SendFileOverHTTP(HttpListenerResponse response, StorageFile s
459462 /// <param name="response"><see cref="HttpListenerResponse"/> to send the content over.</param>
460463 /// <param name="fileName">Name of the file to send over <see cref="HttpListenerResponse"/>.</param>
461464 /// <param name="content">Content of the file to send.</param>
462- public static void SendFileOverHTTP ( HttpListenerResponse response , string fileName , byte [ ] content )
465+ /// /// <param name="contentType">The type of file, if empty string, then will use auto detection</param>
466+ public static void SendFileOverHTTP ( HttpListenerResponse response , string fileName , byte [ ] content , string contentType = "" )
463467 {
464- string ContentType = GetContentTypeFromFileName ( fileName . Substring ( fileName . LastIndexOf ( '.' ) ) ) ;
468+ contentType = contentType == "" ? GetContentTypeFromFileName ( fileName . Substring ( fileName . LastIndexOf ( '.' ) ) ) : contentType ;
465469
466470 try
467471 {
468- response . ContentType = ContentType ;
472+ response . ContentType = contentType ;
469473 response . ContentLength64 = content . Length ;
470474
471475 // Now loop to send all the data.
@@ -480,7 +484,7 @@ public static void SendFileOverHTTP(HttpListenerResponse response, string fileNa
480484 response . OutputStream . Write ( content , ( int ) bytesSent , ( int ) bytesToSend ) ;
481485
482486 // allow some time to physically send the bits. Can be reduce to 10 or even less if not too much other code running in parallel
483-
487+
484488 // update bytes sent
485489 bytesSent += bytesToSend ;
486490 }
@@ -658,7 +662,6 @@ private void ListInterfaces()
658662 }
659663 }
660664
661- /// Get the MIME-type for a file name.
662665 /// <summary>
663666 /// Get the MIME-type for a file name.
664667 /// </summary>
0 commit comments