+ size_t pos = url.find("?frag=");
+ if (pos != string::npos) {
+ // Parse an endpoint of the type /stream.mp4?frag=1234-5678.
+ const char *ptr = url.c_str() + pos + 6;
+
+ // "?frag=header" is special.
+ if (strcmp(ptr, "header") == 0) {
+ client->stream_pos = Client::STREAM_POS_HEADER_ONLY;
+ client->stream_pos_end = -1;
+ } else {
+ char *endptr;
+ long long frag_start = strtol(ptr, &endptr, 10);
+ if (ptr == endptr || frag_start < 0 || frag_start == LLONG_MAX) {
+ return 400; // Bad request.
+ }
+ if (*endptr != '-') {
+ return 400; // Bad request.
+ }
+ ptr = endptr + 1;
+
+ long long frag_end = strtol(ptr, &endptr, 10);
+ if (ptr == endptr || frag_end < frag_start || frag_end == LLONG_MAX) {
+ return 400; // Bad request.
+ }
+
+ if (*endptr != '\0') {
+ return 400; // Bad request.
+ }
+
+ client->stream_pos = frag_start;
+ client->stream_pos_end = frag_end;
+ }
+ url = url.substr(0, pos);
+ } else {
+ client->stream_pos = -1;
+ client->stream_pos_end = -1;
+ }