API Reference › Http › Http.expected
method

Http.expected

Http.expected(handle) -> int

Returns the length of the response body as the server announced it (Content-Length), or -1 while that is not known. For a request given Http.save_to it is known as soon as the headers arrive, and stays -1 for a reply sent without a length (chunked) — draw an indeterminate bar then. For an ordinary in-memory request it is -1 until the reply lands, then the body length.

Example

program Demo {
  entry {
    let h = Http.open("GET", "https://example.com/big.bin")
    Http.save_to(h, "big.bin.part")
    Http.send(h)
    print(Http.expected(h))   # -1: nothing has arrived yet
  }
}
← All symbols