RRangeTallow
Workflows

Coding workflows · Single HTTP byte ranges

03
Built around your work

A concrete starting point

Resolve one ASCII HTTP byte range against a resource size from zero through 10^12 using a header of at most 80 characters. Test open ends and suffixes, clip an excessive end and return no interval for unsatisfiable requests while rejecting malformed or multiple ranges.

01

Open the context

Choose the project folder and name the files or behavior involved.

02

Define the change

Describe the input, expected output and boundaries that must stay intact.

03

Inspect the work

Review the proposed edits and any commands before relying on their result.

04

Check the outcome

Compare actual behavior with the expected result. If a check fails, investigate it before applying more changes.

Single HTTP byte ranges

A concrete starting point
import re

def byte_range(header, size):
    if type(header) is not str or len(header) > 80 or type(size) is not int or not 0 <= size <= 10**12:
        raise ValueError("range.input")
    match = re.fullmatch(r"bytes=([0-9]*)-([0-9]*)", header)
    if match is None or not any(match.groups()):
        raise ValueError("range.syntax")
    left, right = match.groups()
    if not left:
        suffix = int(right)
        if suffix == 0 or size == 0:
            return None
        return max(0, size-suffix), size-1
    start = int(left)
    end = int(right) if right else size-1
    if start >= size or end < start:
        return None
    return start, min(end, size-1)

The example is a starting point for a real project, not a claim that generated code is already tested. Adjust paths, dependencies and expected behavior to match your application.

AI coding workspace

Your next change starts here.

Get the Windows app ↗