Mila
Deep Neural Network Library
Loading...
Searching...
No Matches
HttpClient.ixx File Reference

How to ask, and how to read the answer: redirects, the token rule, resume, status. More...

#include <cstddef>
#include <cstdint>
#include <format>
#include <functional>
#include <memory>
#include <stdexcept>
#include <string>
#include <utility>
import Distribution.HttpTransport;

Classes

class  Mila::Distribution::HttpClient
 GET a URL, streaming the body to a sink, over whichever transport it is given. More...
struct  Mila::Distribution::HttpRequest
struct  Mila::Distribution::HttpResult

Namespaces

namespace  Mila
 Mila main API namespace.

Typedefs

using Mila::Distribution::ProgressCallback
 Called as bytes arrive.

Enumerations

enum class  Mila::Distribution::HttpStatus {
  Ok , Unauthorized , Forbidden , NotFound ,
  RangeIgnored , RangeNotSatisfiable , TransportError , ServerError
}
 Outcome of a transfer attempt, distinguishing failures that need different fixes. More...

Functions

std::string Mila::Distribution::hostOf (const std::string &url)
 Extract the host from a URL, for deciding whether auth may cross a redirect.
std::string Mila::Distribution::resolveRedirect (const std::string &base, const std::string &location)
 Resolve a Location header against the URL it came from.
std::string Mila::Distribution::toString (HttpStatus status)

Detailed Description

How to ask, and how to read the answer: redirects, the token rule, resume, status.

Every decision that used to live inside the libcurl implementation, now written once above any transport and depending on nothing. That matters most for one rule: the authorization header is dropped when the host changes, so no transport can leak a bearer token to a CDN, because no transport is ever told one. See Specifications/HttpClient.md.

Typedef Documentation

◆ ProgressCallback

Initial value:
std::function<bool( uint64_t bytes_so_far, uint64_t total_bytes )>

Called as bytes arrive.

Return false to abort the transfer.

total_bytes is zero when the server does not report a length.

Enumeration Type Documentation

◆ HttpStatus

enum class Mila::Distribution::HttpStatus
exportstrong

Outcome of a transfer attempt, distinguishing failures that need different fixes.

Enumerator
Ok 

Transfer completed.

Unauthorized 

401 – no token, or the token is not valid.

Forbidden 

403 – token valid, but the repository's terms are not accepted.

NotFound 

404 – wrong coordinate, revision or file path.

RangeIgnored 

A range request drew a 200; the partial must be discarded.

RangeNotSatisfiable 

416 on a resume; the offset is at or past the end of the file.

TransportError 

Connection, TLS or I/O failure.

ServerError 

5xx.

Function Documentation

◆ resolveRedirect()

std::string Mila::Distribution::resolveRedirect ( const std::string & base,
const std::string & location )
export

Resolve a Location header against the URL it came from.

A Location may be relative – RFC 7231 permits it and HuggingFace uses it, answering a manifest request with a 307 to /api/resolve-cache/.... Handing that to a transport verbatim yields a malformed URL, since a bare path has no scheme.

Handles the four forms: absolute, protocol-relative, root-relative, and path-relative.