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/. */
7 #ifndef ContentRange_h__
8 #define ContentRange_h__
10 #include "mozilla/Maybe.h"
12 #include "nsISupportsImpl.h"
14 // nsIBaseChannel subclasses may support range headers when accessed via
15 // Fetch or XMLHTTPRequest, even if they are not HTTP assets and so do not
16 // normally have access to headers (such as the blob URLs). The ContentRange
17 // class helps to encapsulate much of the common logic involved in parsing,
18 // storing, validating, and writing out Content-Range headers.
20 namespace mozilla::net
{
24 ~ContentRange() = default;
31 uint64_t Start() const { return mStart
; }
32 uint64_t End() const { return mEnd
; }
33 uint64_t Size() const { return mSize
; }
34 bool IsValid() const { return mStart
< mSize
; }
35 ContentRange(uint64_t aStart
, uint64_t aEnd
, uint64_t aSize
)
36 : mStart(aStart
), mEnd(aEnd
), mSize(aSize
) {}
37 ContentRange(const nsACString
& aRangeHeader
, uint64_t aSize
);
38 void AsHeader(nsACString
& aOutString
) const;
40 NS_INLINE_DECL_REFCOUNTING(ContentRange
)
43 } // namespace mozilla::net
45 #endif // ContentRange_h__