2

If a web service only needs the first part of a file (e.g. generating a thumbnail of the first page of a PDF file), is it possible for the service to send a response that terminates the request once it has all the information it needs, so the client doesn't upload the rest of the file?

Alf Eaton
  • 5,226
  • 4
  • 45
  • 50

1 Answers1

1

In a somewhat brutish way, yes it is. By disconnecting. From RFC 7230, section 6.3.1:

Connections can be closed at any time, with or without intention.

There is no real way to let the client know it is not to retry the request, though. It all boils down to whether the request method has been idempotent or not. From the same section:

When an inbound connection is closed prematurely, a client MAY open a new connection and automatically retransmit an aborted sequence of requests if all of those requests have idempotent methods.

Your real problem here is that you are at a point in the client-server communication where there is no way the server can give any feedback on an uploaded data chunk. The last chance for this were right after reading the headers from the client, but that won't give you the information you obviously want. You could try and implement partial uploads through separate requests, but that will open up other problems. Besides, you will forfeit restfulness.

If you are willing to go that route, you may profit from little known features such as expectation negotiation and chunk extensions. Possibly both.

As-is, you stand little chance in succeeding as e.g. PHP is having a hard time aborting uploads. Same goes for Python. Node.js can actually do this if running on its own. However, that solution is really hackish and depends on clients to be very accommodating.

Community
  • 1
  • 1
DaSourcerer
  • 6,288
  • 5
  • 32
  • 55