+ Stream *stream = client->stream;
+
+ if (client->serving_hls_playlist) {
+ if (stream->encoding == Stream::STREAM_ENCODING_METACUBE) {
+ // This doesn't make any sense, and is hard to implement, too.
+ return 404;
+ } else {
+ return 200;
+ }
+ }
+
+ if (client->stream_pos_end == Client::STREAM_POS_NO_END) {
+ if (stream->unavailable) {
+ return 503; // Service unavailable.
+ }
+
+ // This stream won't end, so we don't have a content-length,
+ // and can just as well tell the client it's Connection: close
+ // (otherwise, we'd have to implement chunking TE for no good reason).
+ client->close_after_response = true;
+ } else {
+ if (stream->encoding == Stream::STREAM_ENCODING_METACUBE) {
+ // This doesn't make any sense, and is hard to implement, too.
+ return 416; // Range not satisfiable.
+ }
+
+ // Check that we have the requested fragment in our backlog.
+ size_t buffer_end = stream->bytes_received;
+ size_t buffer_start = (buffer_end <= stream->backlog_size) ? 0 : buffer_end - stream->backlog_size;
+
+ if (client->stream_pos_end > buffer_end ||
+ client->stream_pos < buffer_start) {
+ return 416; // Range not satisfiable.
+ }