Can the server respond with content-length less than requested range if proper headers are used

Solution 1:

If you can't satisfy the requested range, you want to respond with 416, and include a Content-Range header telling the client what the satisfiable range actually is. See

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/416

If you're really going to handle range requests yourself, you probably want to read the RFC. You need to gracefully handle badly formatted requests, unknown units, multiple ranges, etc. The page I linked above has a link to the current RFC.