tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ContentRange.h (1460B)


      1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim:set et cin ts=4 sw=2 sts=2: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef ContentRange_h__
      8 #define ContentRange_h__
      9 
     10 #include "nsString.h"
     11 #include "nsISupportsImpl.h"
     12 
     13 // nsIBaseChannel subclasses may support range headers when accessed via
     14 // Fetch or XMLHTTPRequest, even if they are not HTTP assets and so do not
     15 // normally have access to headers (such as the blob URLs). The ContentRange
     16 // class helps to encapsulate much of the common logic involved in parsing,
     17 // storing, validating, and writing out Content-Range headers.
     18 
     19 namespace mozilla::net {
     20 
     21 class ContentRange {
     22 private:
     23  ~ContentRange() = default;
     24 
     25  uint64_t mStart{0};
     26  uint64_t mEnd{0};
     27  uint64_t mSize{0};
     28 
     29 public:
     30  uint64_t Start() const { return mStart; }
     31  uint64_t End() const { return mEnd; }
     32  uint64_t Size() const { return mSize; }
     33  bool IsValid() const { return mStart < mSize; }
     34  ContentRange(uint64_t aStart, uint64_t aEnd, uint64_t aSize)
     35      : mStart(aStart), mEnd(aEnd), mSize(aSize) {}
     36  ContentRange(const nsACString& aRangeHeader, uint64_t aSize);
     37  void AsHeader(nsACString& aOutString) const;
     38 
     39  NS_INLINE_DECL_REFCOUNTING(ContentRange)
     40 };
     41 
     42 }  // namespace mozilla::net
     43 
     44 #endif  // ContentRange_h__