CSE312 — Web Development
POST /form-path HTTP/1.1
Content-Length: 746
Content-Type: multipart/form-data; boundary=----WebKitFormBoundarycriD3u6M0UuPR1ia
------WebKitFormBoundarycriD3u6M0UuPR1ia
Content-Disposition: form-data; name="commenter"
Jesse
------WebKitFormBoundarycriD3u6M0UuPR1ia
Content-Disposition: form-data; name="upload"; filename="discord.png"
Content-Type: image/png
<bytes_of_the_file>
------WebKitFormBoundarycriD3u6M0UuPR1ia--bytesRead is how many bytes were actually readPOST /form-path HTTP/1.1
Content-Length: 746
Content-Type: multipart/form-data; boundary=----WebKitFormBoundarycriD3u6M0UuPR1ia
------WebKitFormBoundarycriD3u6M0UuPR1ia
Content-Disposition: form-data; name="commenter"
Jesse
------WebKitFormBoundarycriD3u6M0UuPR1ia
Content-Disposition: form-data; name="upload"; filename="discord.png"
Content-Type: image/png
<bytes_of_the_file>
------WebKitFormBoundarycriD3u6M0UuPR1ia--POST /form-path HTTP/1.1
Content-Length: 91320
Content-Type: multipart/form-data; boundary=----WebKitFormBoundarycriD3u6M0UuPR1ia
------WebKitFormBoundarycriD3u6M0UuPR1ia
Content-Disposition: form-data; name="commenter"
Jesse
------WebKitFormBoundarycriD3u6M0UuPR1ia
Content-Disposition: form-data; name="upload"; filename="flamingo.jpg"
Content-Type: image/jpeg
<bytes_of_the_file>
------WebKitFormBoundarycriD3u6M0UuPR1ia--POST /form-path HTTP/1.1
Content-Length: 1884206
Content-Type: multipart/form-data; boundary=----WebKitFormBoundarycriD3u6M0UuPR1ia
------WebKitFormBoundarycriD3u6M0UuPR1ia
Content-Disposition: form-data; name="commenter"
Jesse
------WebKitFormBoundarycriD3u6M0UuPR1ia
Content-Disposition: form-data; name="upload"; filename="hq_image.png"
Content-Type: image/png
<bytes_of_the_file>
------WebKitFormBoundarycriD3u6M0UuPR1ia--POST /form-path HTTP/1.1
Content-Length: 1884206
Content-Type: multipart/form-data; boundary=----WebKitFormBoundarycriD3u6M0UuPR1ia
------WebKitFormBoundarycriD3u6M0UuPR1ia
Content-Disposition: form-data; name="commenter"
Jesse
------WebKitFormBoundarycriD3u6M0UuPR1ia
Content-Disposition: form-data; name="upload"; filename="hq_image.png"
Content-Type: image/png
<bytes_of_the_file>
------WebKitFormBoundarycriD3u6M0UuPR1ia--



\r\n\r\nRead returns how many bytes it read. Only use that manybytesRead, err := reader.Read(buffer)
body = append(body, buffer...) // Wrong: Always appends 2048 bytes
body = append(body, buffer[:bytesRead]...) // Right: Only the bytes that were readRead reuses the same buffer every time
Read overwrites them (append copies)buffer (eg. the body from your first parse)Read returns an error, the client disconnected mid-upload
\r\n\r\n)make([]byte, 1000000000)io.ReadAll or io.ReadFull)Range header with the bytes it wants206 Partial Content and only those bytes<video> elements
Accept-Ranges: bytes in every response for an mp4
| Range | Meaning |
|---|---|
bytes={first}-{last} |
Bytes first through last, inclusive |
bytes={first}- |
Bytes first through the end of the file |
bytes=-{n} |
The last n bytes of the file |
bytes=0-50,100-150)
HTTP/1.1 206 Partial Content
Content-Type: video/mp4
Content-Length: 100
Content-Range: bytes 0-99/10000
Accept-Ranges: bytes
X-Content-Type-Options: nosniff
<bytes 0 through 99 of the file>Content-Range: bytes {first}-{last}/{total}
first and last are the bytes you actually senttotal is the size of the entire fileContent-Length is the number of bytes in this response, not the size of the file
last - first + 1bytes=0-99 is 100 bytes, not 99first is past the end of the file, there are no bytes to send416 Range Not SatisfiableContent-Range uses * for the range and still includes the total sizebytes=0-
bytes=0- when the video loads-D - prints the response headers, -o saves the bodypart.bin is exactly 100 bytes