Skip to content

Commit 53b1fbd

Browse files
committed
Update the file upload session section
1 parent cb99f7e commit 53b1fbd

File tree

1 file changed

+80
-44
lines changed

1 file changed

+80
-44
lines changed

peps/pep-0694.rst

Lines changed: 80 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
PEP: 694
32
Title: Upload 2.0 API for Python Package Indexes
43
Author: Barry Warsaw <[email protected]>, Donald Stufft <[email protected]>, Ee Durbin <[email protected]>
@@ -702,11 +701,11 @@ the file to be uploaded. These checks may include, but are not limited to:
702701
- checking if the contents of the ``metadata``, if provided, are valid.
703702

704703
If the server determines that upload should proceed, it will return a ``202 Accepted`` response, with the
705-
response body below. The :ref:`status <publishing-session-status>` of the session will also include the filename in the
706-
``files`` mapping. If the server cannot proceed with an upload because the ``mechanism`` supplied by the
707-
client is not supported it **MUST** return a ``422 Unprocessable Content``. The server **MAY** allow parallel
708-
uploads of files, but is not required to. If the server determines the upload cannot proceed, it **MUST**
709-
return a ``409 Conflict``.
704+
response body below. The :ref:`status <publishing-session-status>` of the publishing session will also
705+
include the filename in the ``files`` mapping. If the server cannot proceed with an upload because the
706+
``mechanism`` supplied by the client is not supported it **MUST** return a ``422 Unprocessable Content``. The
707+
server **MAY** allow parallel uploads of files, but is not required to. If the server determines the upload
708+
cannot proceed, it **MUST** return a ``409 Conflict``.
710709

711710
.. _file-upload-session-response:
712711

@@ -733,8 +732,8 @@ The successful response includes the following:
733732
}
734733
}
735734
736-
A ``Retry-After`` response header **MUST** be present
737-
to indicate to clients when they should next poll for an updated status.
735+
A ``Retry-After`` response header **MUST** be present to indicate to clients when they should next poll for an
736+
updated status.
738737

739738
Besides the ``meta`` key, which has the same format as the request JSON, the success response has
740739
the following keys:
@@ -765,14 +764,14 @@ the following keys:
765764
File Upload Session Links
766765
+++++++++++++++++++++++++
767766

768-
For the ``links`` key in the success JSON, the following sub-keys are valid:
767+
For the ``links`` key in the response payload, the following sub-keys are valid:
769768

770769
``file-upload-session``
771-
The endpoint where actions for this file-upload-session can be performed.
772-
including :ref:`canceling and discarding the file upload session <file-upload-session-cancellation>`,
773-
:ref:`querying the current file upload session status <publishing-session-status>`,
774-
and :ref:`requesting an extension of the file upload session lifetime <publishing-session-extension>`
775-
(*if* the server supports it).
770+
The endpoint where actions for this file-upload-session can be performed. including :ref:`completing a
771+
file upload session <file-upload-session-completion>`, :ref:`canceling and discarding the file upload
772+
session <file-upload-session-cancellation>`, :ref:`querying the current file upload session status
773+
<file-upload-session-status>`, and :ref:`requesting an extension of the file upload session lifetime
774+
<file-upload-session-extension>` (*if* the server supports it).
776775

777776
.. _file-upload-session-completion:
778777

@@ -794,42 +793,40 @@ The requests looks like:
794793
"action": "complete",
795794
}
796795
797-
If the server is able to immediately complete the file upload session, it may do so and return a
798-
``201 Created`` response and set the status of the file upload session to ``complete``.
799-
If it is unable to immediately complete the file upload session
800-
(for instance, if it needs to do validation that may take longer than reasonable in a single HTTP
801-
request), then it may return a ``202 Accepted`` response
802-
and set the status of the file upload session to ``processing``.
796+
If the server is able to immediately complete the file upload session, it may do so and return a ``201
797+
Created`` response and set the status of the file upload session to ``complete``. If it is unable to
798+
immediately complete the file upload session (for instance, if it needs to do validation that may take longer
799+
than reasonable in a single HTTP request), then it may return a ``202 Accepted`` response and set the status
800+
of the file upload session to ``processing``.
803801

804-
In either case, the server should include a ``Location`` header pointing back to the File Upload
805-
Session status URL.
802+
In either case, the server should include a ``Location`` header pointing back to the :ref:`file upload session
803+
status <file-upload-session-status>` URL.
806804

807-
Servers **MUST** allow clients to poll the file upload session status URL
808-
to watch for the status to change.
809-
If the server responds with a ``202 Accepted``,
810-
clients may poll the file upload session status URL to watch for the status to change.
811-
Clients **SHOULD** respect the ``Retry-After`` header value
812-
of the file upload session status response.
805+
Servers **MUST** allow clients to poll the file upload session status URL to watch for the status to change.
806+
If the server responds with a ``202 Accepted``, clients may poll the file upload session status URL to watch
807+
for the status to change. Clients **SHOULD** respect the ``Retry-After`` header value of the file upload
808+
session status response.
813809

814-
If an error occurs, the appropriate ``4xx`` code should be returned, as described in the
815-
:ref:`session-errors` section.
810+
**FIXME**: Errors
811+
812+
If an error occurs, the appropriate ``4xx`` code should be returned, as described in the :ref:`session-errors`
813+
section.
816814

817815

818816
.. _file-upload-session-cancellation:
819817

820818
Cancellation and Deletion
821819
~~~~~~~~~~~~~~~~~~~~~~~~~
822820

823-
A client can cancel an in-progress file upload session, or delete a file that has been
824-
completely uploaded. In both cases, the client performs this by issuing a ``DELETE`` request to
825-
the file upload session URL of the file they want to delete.
821+
A client can cancel an in-progress file upload session, or delete a file that has been completely uploaded.
822+
In both cases, the client performs this by issuing a ``DELETE`` request to the ``links.file-upload-session``
823+
URL from the :ref:`file upload session creation response <file-upload-session-response>` of the file they want
824+
to delete.
826825

827826
A successful deletion request **MUST** respond with a ``204 No Content``.
828827

829-
Once canceled or deleted, a client **MUST NOT** assume that
830-
the previous file upload session resource
831-
or associated file upload mechanisms
832-
can be reused.
828+
Once canceled or deleted, a client **MUST NOT** assume that the previous file upload session resource or
829+
associated file upload mechanisms can be reused.
833830

834831

835832
Replacing a Partially or Fully Uploaded File
@@ -838,13 +835,52 @@ Replacing a Partially or Fully Uploaded File
838835
To replace a session file, the file upload **MUST** have been previously completed, canceled, or
839836
deleted. It is not possible to replace a file if the upload for that file is in-progress.
840837

841-
To replace a session file, clients should
842-
:ref:`cancel and delete the in-progress upload <file-upload-session-cancellation>` by
843-
issuing a ``DELETE`` to the upload resource URL for the file they want to replace.
844-
After this, the new file upload can be initiated by beginning
845-
the entire :ref:`file upload <file-upload-session>` sequence over again.
846-
This means providing the metadata request again to retrieve a new upload resource URL.
847-
Clients **MUST NOT** assume that the previous upload resource URL can be reused after deletion.
838+
To replace a session file, clients should :ref:`cancel and delete the in-progress upload
839+
<file-upload-session-cancellation>` first. After this, the new file upload can be initiated by beginning the
840+
entire :ref:`file upload <file-upload-session>` sequence over again. This means providing the metadata
841+
request again to retrieve a new upload resource URL. Clients **MUST NOT** assume that the previous upload
842+
resource URL can be reused after deletion.
843+
844+
.. _file-upload-session-status:
845+
846+
File Upload Session Status
847+
~~~~~~~~~~~~~~~~~~~~~~~~~~
848+
849+
The client can query status of the file upload session by issuing a ``GET`` request to the
850+
``links.file-upload-session`` URL from the :ref:`file upload session creation response
851+
<file-upload-session-response>`. The server responds to this request with the same payload as the file upload
852+
session creation response, except with any changes ``status`` and ``expires-at`` reflected.
853+
854+
.. _file-upload-session-extension:
855+
856+
File Upload Session Extension
857+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
858+
859+
Servers **MAY** allow clients to extend file upload sessions, but the overall lifetime and number of
860+
extensions allowed is left to the server. To extend a file upload session, a client issues a ``POST`` request
861+
to the ``links.file-upload-session`` URL from the :ref:`file upload session creation response
862+
<file-upload-session-response>`.
863+
864+
The request looks like:
865+
866+
.. code-block:: json
867+
868+
{
869+
"meta": {
870+
"api-version": "2.0"
871+
},
872+
"action": "extend",
873+
"extend-for": 3600
874+
}
875+
876+
The number of seconds specified is just a suggestion to the server for the number of additional seconds to
877+
extend the current file upload session. For example, if the client wants to extend session for another hour,
878+
``extend-for`` would be ``3600``. Upon successful extension, the server will respond with the same :ref:`file
879+
upload session creation response body <file-upload-session-response>` that they got when they initially
880+
created the publishing session, except with any changes to ``status`` or ``expires-at`` reflected.
881+
882+
If the server refuses to extend the session for the requested number of seconds, it **MUST** still return a
883+
success response, and the ``expires-at`` key will simply reflect the current expiration time of the session.
848884

849885

850886
.. _staged-preview:

0 commit comments

Comments
 (0)