refactor(media): upload pieces are PUT, not PATCH
A piece at an offset is idempotent, which is what PUT means. Java's HttpURLConnection, which the Kotlin port uses, refuses PATCH outright. nginx also retries PUT on the next upstream by default but never PATCH, so the docs now only ask for non_idempotent on the start/status POST. The protocol is unreleased, so nothing else depends on the old method. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -81,7 +81,7 @@ describe('pieces', () => {
|
||||
let patches = 0;
|
||||
let sentBytes = 0;
|
||||
const flaky: typeof fetch = (async (input: RequestInfo | URL, init?: RequestInit) => {
|
||||
if (init?.method === 'PATCH') {
|
||||
if (init?.method === 'PUT') {
|
||||
patches++;
|
||||
// Piece 2, first try: the connection drops before the relay gets it.
|
||||
if (patches === 2) throw new Error('connection reset');
|
||||
@@ -117,7 +117,7 @@ describe('pieces', () => {
|
||||
});
|
||||
const piece = (base: string, offset: number, length: number) =>
|
||||
fetch(`${base}/v1/media/${id}/upload`, {
|
||||
method: 'PATCH',
|
||||
method: 'PUT',
|
||||
headers: { [OFFSET_HEADER]: String(offset), ...owner.headers({ op: 'piece', id, offset, length }) },
|
||||
body: bytes.slice(offset, offset + length),
|
||||
});
|
||||
@@ -156,7 +156,7 @@ describe('pieces', () => {
|
||||
const start = () => req('POST', { 'x-shade-size': String(size), ...owner.headers({ op: 'upload', id, size, readTokenHash: '' }) });
|
||||
const piece = (offset: number, length = Math.min(chunk, size - offset), who = owner) =>
|
||||
req(
|
||||
'PATCH',
|
||||
'PUT',
|
||||
{ 'content-length': String(length), [OFFSET_HEADER]: String(offset), ...who.headers({ op: 'piece', id, offset, length }) },
|
||||
bytes.slice(offset, offset + length),
|
||||
);
|
||||
@@ -176,7 +176,7 @@ describe('pieces', () => {
|
||||
expect((await piece(0, chunk, OwnerKey.generate())).status).toBe(404); // someone else's upload
|
||||
// A signature over one offset does not carry another.
|
||||
const replay = await req(
|
||||
'PATCH',
|
||||
'PUT',
|
||||
{ 'content-length': String(chunk), [OFFSET_HEADER]: '0', ...owner.headers({ op: 'piece', id, offset: chunk, length: chunk }) },
|
||||
bytes.slice(0, chunk),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user