Skip to content

Commit 5ef177e

Browse files
committed
refinements
1 parent daf06f4 commit 5ef177e

1 file changed

Lines changed: 70 additions & 34 deletions

File tree

peps/pep-0694.rst

Lines changed: 70 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ these steps:
152152

153153
#. Initiate an upload session, creating a release stage.
154154
#. Initiate file-upload session(s) to that stage as part of the upload session.
155-
#. Complete the file-upload session(s).
155+
#. Execute file upload mechanism for the file-upload session(s).
156+
#. Complete the file-upload session(s), marking them as executed or canceled.
156157
#. Complete the upload session, publishing or discarding the stage.
157158
#. Optionally check the status of an upload session.
158159

@@ -179,8 +180,6 @@ Specifically for PyPI, this PEP proposes to implement the root endpoint at
179180
being tested, and will be blessed as permanent after sufficient testing with live projects.
180181

181182

182-
183-
184183
.. _session-create:
185184

186185
Create an Upload Session
@@ -251,6 +250,7 @@ The successful response includes the following JSON content:
251250
"upload": "...",
252251
"session": "...",
253252
},
253+
"mechanisms": ["http-post-application-octet-stream"],
254254
"session-token": "<token-string>",
255255
"valid-for": 604800,
256256
"status": "pending",
@@ -268,6 +268,9 @@ the following keys:
268268
A dictionary mapping :ref:`keys to URLs <session-links>` related to this session, the details of
269269
which are provided below.
270270

271+
``mechanisms``
272+
A list of file-upload mechanisms supported by the server.
273+
271274
``session-token``
272275
If the index supports :ref:`previewing staged releases <staged-preview>`, this key will contain
273276
the unique :ref:`"session token" <session-token>` that can be provided to installers in order to
@@ -330,13 +333,9 @@ The ``files`` key contains a mapping from the names of the files uploaded in thi
330333
sub-mapping with the following keys:
331334

332335
``status``
333-
A string with valid values ``partial``, ``pending``, ``complete``, and ``error``. If a file
334-
upload has not seen an ``Upload-Complete: ?1`` header, then ``partial`` will be returned. If
335-
``Upload-Complete: ?1`` resulted in a ``202 Accepted``, then ``pending`` will be returned until
336-
asynchronous processing of the last chunk and the full file has been completed. If a ``201
337-
Created`` was returned, or the last chunk processing is finished, ``complete`` will be returned.
336+
A string with valid values ``pending``, ``processing``, ``complete``, ``error``, and ``canceled``.
338337
If there was an error during upload, then clients should not assume the file is in any usable
339-
state, ``error`` will be returned and it's best to :ref:`cancel or delete <cancel-an-upload>`
338+
state, ``error`` will be returned and it's best to :ref:`cancel or delete <file-upload-session-cancelation>`
340339
the file and start over. This action would remove the file name from the ``files`` key of the
341340
:ref:`session status response body <session-response>`.
342341

@@ -378,7 +377,7 @@ request body has the following JSON format:
378377
"size": 1000,
379378
"hashes": {"sha256": "...", "blake2b": "..."},
380379
"metadata": "...",
381-
"mechanisms": ["http-post-application-octet-stream"]
380+
"mechanism": "http-post-application-octet-stream"
382381
}
383382
384383
@@ -401,14 +400,17 @@ Besides the standard ``meta`` key, the request JSON has the following additional
401400

402401
Multiple hashes may be passed at a time, but all hashes provided **MUST** be valid for the file.
403402

403+
``mechanism`` (**required**)
404+
The file-upload mechanisms the client intends to use for this file.
405+
This mechanism **SHOULD** be chosen from the list of mechanisms advertised in the `session response body
406+
<session-response>`_.
407+
A client **MAY** send a mechanism that is not advertised in cases where server operators have
408+
documented a new or up-coming mechanism that is available for use on a "pre-release" basis.
409+
404410
``metadata`` (**optional**)
405411
If given, this is a string value containing the file's `core metadata
406412
<https://packaging.python.org/en/latest/specifications/core-metadata/>`_.
407413

408-
``mechanisms`` (**optional**)
409-
If given this string value contains the file-upload mechanisms supported by the client.
410-
The server **MAY** use this list to inform the contents of ``mechanisms`` in its response.
411-
412414
Servers **MAY** use the data provided in this request to do some sanity checking prior to allowing
413415
the file to be uploaded. These checks may include, but are not limited to:
414416

@@ -421,11 +423,13 @@ the file to be uploaded. These checks may include, but are not limited to:
421423
If the server determines that upload should proceed, it will return a ``202 Accepted`` response, with
422424
the response body below. The :ref:`status <session-status>` of the session will also include the filename in the ``files`` mapping. If the server determines the upload cannot proceed, it **MUST** return
423425
a ``409 Conflict``. The server **MAY** allow parallel uploads of files, but is not required to.
426+
If the server cannot proceed with an upload because the ``mechanism`` supplied by the client is not supported
427+
it **MUST** return a ``422 Unprocessable Entity``.
424428

425-
.. _upload-session-response:
429+
.. _file-upload-session-response:
426430

427-
Response Body
428-
+++++++++++++
431+
File Upload Session Response Body
432+
+++++++++++++++++++++++++++++++++
429433

430434
The successful response includes the following JSON content:
431435

@@ -436,10 +440,12 @@ The successful response includes the following JSON content:
436440
"api-version": "2.0"
437441
},
438442
"links": {
443+
"session": "...",
439444
"file-upload-session": "..."
440445
},
441-
"upload-session-id": "<a string identifying the upload session>",
442-
"mechanisms": {
446+
"status": "pending",
447+
"valid-for": 3600,
448+
"mechanism": {
443449
"http-post-application-octet-stream": {
444450
"url": "..."
445451
}
@@ -450,13 +456,32 @@ The successful response includes the following JSON content:
450456
Besides the ``meta`` key, which has the same format as the request JSON, the success response has
451457
the following keys:
452458

453-
``upload-session-id``
454-
The unique file-upload session identifier.
459+
``links``
460+
A dictionary mapping :ref:`keys to URLs <file-upload-session-links>` related to this session,
461+
the details of which are provided below.
455462

456-
``mechanisms``
457-
A mapping containing the mechanism identifier that the server supports, to a mapping
458-
containing details necessary to execute each mechanism.
463+
``mechanism``
464+
A mapping containing the supported mechanism identifier negotiated by the client and server,
465+
to a mapping containing details necessary to execute the mechanism.
459466

467+
.. _file-upload-session-links:
468+
469+
Session Links
470+
+++++++++++++
471+
472+
For the ``links`` key in the success JSON, the following sub-keys are valid:
473+
474+
``session``
475+
The endpoint where actions for the parent session can be performed.
476+
477+
``file-upload-session``
478+
The endpoint where actions for this file-upload-session can be performed.
479+
including :ref:`canceling and discarding the file upload session <file-upload-session-cancelation>`,
480+
:ref:`querying the current file upload session status <session-status>`,
481+
and :ref:`requesting an extension of the file upload session lifetime <session-extension>`
482+
(*if* the server supports it).
483+
484+
.. _file-upload-session-completion:
460485

461486
File Upload Session Completion
462487
++++++++++++++++++++++++++++++
@@ -477,7 +502,14 @@ The JSON body of this requests looks like:
477502
}
478503
479504
480-
.. _cancel-an-upload:
505+
After receiving this requests the server **MAY** perform additional asynchronous processing on the file,
506+
for instance to verify its hashes or contents.
507+
If the processing is required to complete before an upload session can be published,
508+
the status of the file upload session can be set to ``processing`` until such processing is complete,
509+
reaches an error state, or the file upload session is canceled.
510+
511+
512+
.. _file-upload-session-cancelation:
481513

482514
Canceling and Deleting File Uploads
483515
+++++++++++++++++++++++++++++++++++
@@ -499,7 +531,7 @@ To replace a session file, the file upload **MUST** have been previously complet
499531
deleted. It is not possible to replace a file if the upload for that file is in-progress.
500532

501533
To replace a session file, clients should :ref:`cancel and delete the in-progress upload
502-
<cancel-an-upload>` by issuing a ``DELETE`` to the upload resource URL for the file they want to
534+
<file-upload-session-cancelation>` by issuing a ``DELETE`` to the upload resource URL for the file they want to
503535
replace. After this, the new file upload can be initiated by beginning the entire :ref:`file upload
504536
<file-uploads>` sequence over again. This means providing the metadata request again to retrieve a
505537
new upload resource URL. Client **MUST NOT** assume that the previous upload resource URL can be
@@ -511,13 +543,16 @@ reused after deletion.
511543
Session Status
512544
~~~~~~~~~~~~~~
513545

514-
At any time, a client can query the status of the session by issuing a ``GET`` request to the
515-
``session`` :ref:`link <session-links>` given in the :ref:`session creation response body
516-
<session-response>`.
546+
At any time, a client can query the status of a session by issuing a ``GET`` request to the
547+
``session`` :ref:`link <session-links>` or ``file-upload-session`` :ref:`link <file-upload-session-links>`
548+
given in the :ref:`session creation response body <session-response>`
549+
or :ref:`file upload session creation response body <file-upload-session-response>`,
550+
respectively.
517551

518-
The server will respond to this ``GET`` request with the same :ref:`response <session-response>`
519-
that they got when they initially created the upload session, except with any changes to ``status``,
520-
``valid-for``, or ``files`` reflected.
552+
The server will respond to this ``GET`` request with the same :ref:`session response <session-response>`
553+
or :ref:`file upload session creation response body <file-upload-session-response>`,
554+
that they got when they initially created the upload session or file upload session,
555+
except with any changes to ``status``, ``valid-for``, or ``files`` reflected.
521556

522557

523558
.. _session-extension:
@@ -527,8 +562,9 @@ Session Extension
527562

528563
Servers **MAY** allow clients to extend sessions, but the overall lifetime and number of extensions
529564
allowed is left to the server. To extend a session, a client issues a ``POST`` request to the
530-
``session`` :ref:`link <session-links>` given in the :ref:`session creation response body
531-
<session-response>`.
565+
``session`` :ref:`link <session-links>` or ``file-upload-session`` :ref:`link <file-upload-session-links>`
566+
given in the :ref:`session creation response body <session-response>`
567+
or :ref:`file upload session creation response body <file-upload-session-response>`, respectively.
532568

533569
The JSON body of this request looks like:
534570

0 commit comments

Comments
 (0)