cargo::sources::registry::http_remote

Struct HttpRegistry

Source
pub struct HttpRegistry<'gctx> {
Show 17 fields name: InternedString, index_path: Filesystem, cache_path: Filesystem, source_id: SourceId, gctx: &'gctx GlobalContext, url: Url, multi: Multi, requested_update: bool, downloads: Downloads<'gctx>, multiplexing: bool, fresh: HashSet<PathBuf>, fetch_started: bool, registry_config: Option<RegistryConfig>, auth_required: bool, login_url: Option<Url>, auth_error_headers: Vec<String>, quiet: bool,
}
Expand description

A registry served by the HTTP-based registry API.

This type is primarily accessed through the RegistryData trait.

HttpRegistry implements the HTTP-based registry API outlined in RFC 2789. Read the RFC for the complete protocol, but roughly the implementation loads each index file (e.g., config.json or re/ge/regex) from an HTTP service rather than from a locally cloned git repository. The remote service can more or less be a static file server that simply serves the contents of the origin git repository.

Implemented naively, this leads to a significant amount of network traffic, as a lookup of any index file would need to check with the remote backend if the index file has changed. This cost is somewhat mitigated by the use of HTTP conditional fetches (If-Modified-Since and If-None-Match for ETags) which can be efficiently handled by HTTP/2.

Fields§

§name: InternedString

The name of this source, a unique string (across all sources) used as the directory name where its cached content is stored.

§index_path: Filesystem

Path to the registry index ($CARGO_HOME/registry/index/$REG-HASH).

To be fair, HttpRegistry doesn’t store the registry index it downloads on the file system, but other cached data like registry configuration could be stored here.

§cache_path: Filesystem

Path to the cache of .crate files ($CARGO_HOME/registry/cache/$REG-HASH).

§source_id: SourceId

The unique identifier of this registry source.

§gctx: &'gctx GlobalContext§url: Url

Store the server URL without the protocol prefix (sparse+)

§multi: Multi

HTTP multi-handle for asynchronous/parallel requests.

§requested_update: bool

Has the client requested a cache update?

Only if they have do we double-check the freshness of each locally-stored index file.

§downloads: Downloads<'gctx>

State for currently pending index downloads.

§multiplexing: bool

Does the config say that we can use HTTP multiplexing?

§fresh: HashSet<PathBuf>

What paths have we already fetched since the last index update?

We do not need to double-check any of these index files since we have already done so.

§fetch_started: bool

Have we started to download any index files?

§registry_config: Option<RegistryConfig>

Cached registry configuration.

§auth_required: bool

Should we include the authorization header?

§login_url: Option<Url>

Url to get a token for the registry.

§auth_error_headers: Vec<String>

Headers received with an HTTP 401.

§quiet: bool

Disables status messages.

Implementations§

Source§

impl<'gctx> HttpRegistry<'gctx>

Source

pub fn new( source_id: SourceId, gctx: &'gctx GlobalContext, name: &str, ) -> CargoResult<HttpRegistry<'gctx>>

Creates a HTTP-rebased remote registry for source_id.

  • name — Name of a path segment where .crate tarballs and the registry index are stored. Expect to be unique.
Source

fn handle_http_header(buf: &[u8]) -> Option<(&str, &str)>

Splits HTTP HEADER: VALUE to a tuple.

Source

fn start_fetch(&mut self) -> CargoResult<()>

Setup the necessary works before the first fetch gets started.

This is a no-op if called more than one time.

Source

fn handle_completed_downloads(&mut self) -> CargoResult<()>

Checks the results inside the HttpRegistry::multi handle, and updates relevant state in HttpRegistry::downloads accordingly.

Source

fn full_url(&self, path: &Path) -> String

Constructs the full URL to download a index file.

Source

fn is_fresh(&self, path: &Path) -> bool

Check if an index file of path is up-to-date.

The path argument is the same as in RegistryData::load.

Source

fn config_cached(&mut self) -> CargoResult<Option<&RegistryConfig>>

Get the cached registry configuration, if it exists.

Source

fn config(&mut self) -> Poll<CargoResult<&RegistryConfig>>

Get the registry configuration from either cache or remote.

Source

fn add_sleepers(&mut self) -> CargoResult<()>

Moves failed Downloads that are ready to retry to the pending queue.

Trait Implementations§

Source§

impl<'gctx> RegistryData for HttpRegistry<'gctx>

Source§

fn prepare(&self) -> CargoResult<()>

Performs initialization for the registry. Read more
Source§

fn index_path(&self) -> &Filesystem

Returns the path to the index. Read more
Source§

fn assert_index_locked<'a>(&self, path: &'a Filesystem) -> &'a Path

Validates that the global package cache lock is held. Read more
Source§

fn is_updated(&self) -> bool

Is the local cached data up-to-date?
Source§

fn load( &mut self, _root: &Path, path: &Path, index_version: Option<&str>, ) -> Poll<CargoResult<LoadResponse>>

Loads the JSON for a specific named package from the index. Read more
Source§

fn config(&mut self) -> Poll<CargoResult<Option<RegistryConfig>>>

Loads the config.json file and returns it. Read more
Source§

fn invalidate_cache(&mut self)

Invalidates locally cached data.
Source§

fn set_quiet(&mut self, quiet: bool)

If quiet, the source should not display any progress or status messages.
Source§

fn download(&mut self, pkg: PackageId, checksum: &str) -> CargoResult<MaybeLock>

Prepare to start downloading a .crate file. Read more
Source§

fn finish_download( &mut self, pkg: PackageId, checksum: &str, data: &[u8], ) -> CargoResult<File>

Finish a download by saving a .crate file to disk. Read more
Source§

fn is_crate_downloaded(&self, pkg: PackageId) -> bool

Returns whether or not the .crate file is already downloaded.
Source§

fn block_until_ready(&mut self) -> CargoResult<()>

Block until all outstanding Poll::Pending requests are Poll::Ready.

Auto Trait Implementations§

§

impl<'gctx> !Freeze for HttpRegistry<'gctx>

§

impl<'gctx> !RefUnwindSafe for HttpRegistry<'gctx>

§

impl<'gctx> !Send for HttpRegistry<'gctx>

§

impl<'gctx> !Sync for HttpRegistry<'gctx>

§

impl<'gctx> Unpin for HttpRegistry<'gctx>

§

impl<'gctx> !UnwindSafe for HttpRegistry<'gctx>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 736 bytes