QHttpEngine  1.0.0
Simple and secure HTTP server for Qt applications
 All Classes Functions Typedefs Enumerations Enumerator Pages
Public Member Functions | List of all members
QHttpEngine::Range Class Reference

HTTP range representation. More...

#include <qhttpengine/range.h>

Public Member Functions

 Range ()
 Create a new range. More...
 
 Range (const QString &range, qint64 dataSize=-1)
 Construct a range from the provided string. More...
 
 Range (qint64 from, qint64 to, qint64 dataSize=-1)
 Construct a range from the provided offsets. More...
 
 Range (const Range &other, qint64 dataSize)
 Construct a range from the another range's offsets. More...
 
 ~Range ()
 Destroy the range.
 
QString contentRange () const
 Retrieve representation suitable for Content-Range header. More...
 
qint64 dataSize () const
 Retrieve dataSize of range. More...
 
qint64 from () const
 Retrieve starting position of range. More...
 
bool isValid () const
 Checks if range is valid. More...
 
qint64 length () const
 Retrieve length of range. More...
 
Rangeoperator= (const Range &other)
 Assignment operator.
 
qint64 to () const
 Retrieve ending position of range. More...
 

Detailed Description

This class provides a representation of HTTP range, described in RFC 7233 and used when partial content is requested by the client. When an object is created, optional dataSize can be specified, so that relative ranges can be represented as absolute.

* QHttpEngine::Range range(10, -1, 90);
* range.from(); // 10
* range.to(); // 89
* range.length(); // 80
*
* range = QHttpEngine::Range("-500", 1000);
* range.from(); // 500
* range.to(); // 999
* range.length(); // 500
*
* range = QHttpEngine::Range(0, -1);
* range.from(); // 0
* range.to(); // -1
* range.length(); // -1
*
* range = QHttpEngine::Range(range, 100);
* range.from(); // 0
* range.to(); // 99
* range.length(); // 100
*

Constructor & Destructor Documentation

QHttpEngine::Range::Range ( )

An empty Range is considered invalid.

QHttpEngine::Range::Range ( const QString &  range,
qint64  dataSize = -1 
)

Parses string representation range and constructs new Range. For raw header "Range: bytes=0-100" only "0-100" should be passed to constructor. dataSize may be supplied so that relative ranges could be represented as absolute values.

QHttpEngine::Range::Range ( qint64  from,
qint64  to,
qint64  dataSize = -1 
)

Initialises a new Range with from and to values. dataSize may be supplied so that relative ranges could be represented as absolute values.

QHttpEngine::Range::Range ( const Range other,
qint64  dataSize 
)

Initialises a new Range with from and to values of other Range. Supplied dataSize is used instead of other dataSize.

Member Function Documentation

QString QHttpEngine::Range::contentRange ( ) const
* QHttpEngine::Range range(0, 100, 1000);
* range.contentRange(); // "0-100/1000"
*
* // When resource size is unknown
* range = QHttpEngine::Range(512, 1024);
* range.contentRange(); // "512-1024/*"
*
* // if range request was bad, return resource size
* range = QHttpEngine::Range(1, 0, 1200);
* range.contentRange(); // "*\/1200"
*
qint64 QHttpEngine::Range::dataSize ( ) const

If dataSize is not set, this method returns -1.

qint64 QHttpEngine::Range::from ( ) const

If range is set as 'last N bytes' and dataSize is not set, returns -N.

bool QHttpEngine::Range::isValid ( ) const

Range is considered invalid if it is out of bounds, that is when this inequality is false - (from <= to < dataSize).

When QHttpRange(const QString&) fails to parse range string, resulting range is also considered invalid.

* QHttpEngine::Range range(1, 0, -1);
* range.isValid(); // false
*
* range = QHttpEngine::Range(512, 1024);
* range.isValid(); // true
*
* range = QHttpEngine::Range("-");
* range.isValid(); // false
*
* range = QHttpEngine::Range("abccbf");
* range.isValid(); // false
*
* range = QHttpEngine::Range(0, 512, 128);
* range.isValid(); // false
*
* range = QHttpEngine::Range(128, 64, 512);
* range.isValid(); // false
*
qint64 QHttpEngine::Range::length ( ) const

If ending position is not set, and dataSize is not set, and range is not set as 'last N bytes', returns -1. If range is invalid, returns -1.

qint64 QHttpEngine::Range::to ( ) const

If range is set as 'last N bytes' and dataSize is not set, returns -1. If ending position is not set, and dataSize is not set, returns -1.


The documentation for this class was generated from the following file: