Skip to content

Commit f9505ab

Browse files
committed
Merge pull request #139 from lappkast/master
Added method browse_file which takes root_path as argument.
2 parents ad68d17 + 88f0e55 commit f9505ab

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

Suave/Http.fs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,14 @@ module Http =
479479
else raise <| Exception("File canonalization issue.")
480480
else raise <| Exception("File canonalization issue.")
481481

482-
let browse_file file_name =
482+
let browse_file root_path file_name =
483483
fun ({request = r; runtime = q} as h) ->
484-
file (local_file file_name q.home_directory) h
484+
file (local_file file_name root_path) h
485485

486+
let browse_file' file_name =
487+
fun ({request = r; runtime = q} as h) ->
488+
browse_file q.home_directory file_name h
489+
486490
let browse root_path : WebPart =
487491
warbler (fun { request = r; runtime = { logger = l } } ->
488492
Log.verbose l

Suave/Http.fsi

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1343,12 +1343,19 @@ module Http =
13431343
/// </remarks>
13441344
val local_file : file_name:string -> root_path:string -> string
13451345

1346+
/// <summary><para>
1347+
/// 'browse' the file given as the filename, by sending it to the browser with a
1348+
/// MIME-type/Content-Type header based on its extension. Will service from the
1349+
/// root_path.
1350+
/// </para></summary>
1351+
val browse_file : root_path:string -> file_name:string -> WebPart
1352+
13461353
/// <summary><para>
13471354
/// 'browse' the file given as the filename, by sending it to the browser with a
13481355
/// MIME-type/Content-Type header based on its extension. Will service from the
13491356
/// current directory.
13501357
/// </para></summary>
1351-
val browse_file : file_name:string -> WebPart
1358+
val browse_file' : file_name:string -> WebPart
13521359

13531360
/// <summary><para>
13541361
/// 'browse' the file in the sense that the contents of the file are sent based on the

Tests/HttpFile.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ let compression =
3636
testCase "verifiying we get the same size uncompressed" <| fun _ ->
3737
Assert.Equal("length should match"
3838
, test_file_size
39-
, (run_with' (Files.browse_file "test-text-file.txt") |> req_bytes GET "/" None).Length |> int64)
39+
, (run_with' (Files.browse_file' "test-text-file.txt") |> req_bytes GET "/" None).Length |> int64)
4040

4141
testCase "gzip static file" <| fun _ ->
4242
Assert.Equal("length should match"
4343
, test_file_size
44-
, (run_with' (Files.browse_file "test-text-file.txt") |> req_gzip_bytes GET "/" None).Length |> int64)
44+
, (run_with' (Files.browse_file' "test-text-file.txt") |> req_gzip_bytes GET "/" None).Length |> int64)
4545
]

0 commit comments

Comments
 (0)