-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Propagate content length from filesystem through
geny.Writable
and …
…`os.Source` (#320) This means downstream libraries like Requests-Scala or Cask can properly set the content length when handling `os.read.stream`s and similar values in their HTTP requests or responses Noticed the lack of this when uploading to github failed in com-lihaoyi/mill#3686 due to the lack of content length header in the upload Covered by unit tests
- Loading branch information
Showing
4 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package test.os | ||
import utest.{assert => _, _} | ||
|
||
object SourceTests extends TestSuite { | ||
|
||
val tests = Tests { | ||
test("contentMetadata") - TestUtil.prep { wd => | ||
// content type for all files is just treated as application/octet-stream, | ||
// we do not do any clever mime-type inference or guessing | ||
(wd / "folder1/one.txt").toSource.httpContentType ==> Some("application/octet-stream") | ||
// length is taken from the filesystem at the moment at which `.toSource` is called | ||
(wd / "folder1/one.txt").toSource.contentLength ==> Some(22) | ||
(wd / "File.txt").toSource.contentLength ==> Some(8) | ||
|
||
// Make sure the `Writable` returned by `os.read.stream` propagates the content length | ||
os.read.stream(wd / "folder1/one.txt").contentLength ==> Some(22) | ||
// Even when converted to an `os.Source` | ||
(os.read.stream(wd / "folder1/one.txt"): os.Source).contentLength ==> Some(22) | ||
} | ||
} | ||
} |