matlab.net.http.io.MultipartConsumer Class
Namespace: matlab.net.http.io
Superclasses: matlab.net.http.io.GenericConsumer
Helper for multipart content types in HTTP messages
Description
This consumer processes multipart HTTP response messages. A multipart message is one whose
Content-Type header field specifies "multipart"
, and whose body contains
one or more parts. Each part contains its own set of header fields describing the part, the
most important of which is a Content-Type field.
The matlab.net.http.io.MultipartConsumer
class is a handle
class.
Subclass Authors
If you are writing your own ContentConsumer
, it will generally work
whether it is a top level consumer (specified as the 3rd argument to the
RequestMessage.send
method) or a part of a multipart message (when
specified as a "delegate" in the MultipartConsumer
constructor call).
MultipartConsumer
makes it appear to each delegate as if it was handling
the entire response message, while actually assembling the results into an array of
ResponseMessages
stored in the returned
response.Body.Data
property.
The following describes the MultipartConsumer
behavior:
Each time this MultipartConsumer
receives a complete part of a message
from the server, it parses any headers in the part and then invokes the appropriate delegate
consumer appropriate for the Content-Type field in the part. If there is no Content-Type
field in the part, it assumes the type is text/plain
. If there is no
delegate able to handle the type, it uses default processing for the part based on the
Content-Type, as described for GenericConsumer
.
MultipartConsumer
does not invoke a delegate until it receives a complete
part. MultipartConsumer
buffers the data for a part, and at the end of
receipt of the part, it copies all the visible properties of ContentConsumer
from this consumer to the delegate, clears the delegate's
Response.Body
, sets the delegate's Header
to the
header of the part, and then calls the delegate's initialize
and
start
methods, followed by one or more calls to the delegate's
putData
method containing the payload of the part, followed by a call to
putData(uint8.empty)
to indicate end-of-data. If the delegate's
initialize
method returns false
to indicate it does
not want to handle the part, the payload of the part is processed using default behavior for
the Content-Type of the part, as described for GenericConsumer
.
If the delegate's start
method returns []
to
indicate that there is no maximum desired buffer size, MultipartConsumer
makes just one call to putData
that provides the entire payload of the
part, followed by the end-of-data call. Otherwise it calls putData
enough
times to supply the entire payload in units of the buffer size.
If the delegate's putData
method sets the STOP
return value to true
to indicate that it does not want any more data,
then MultipartConsumer
closes the connection to end the transfer, as if the
message had ended. In this way the delegate controls whether the remainder of the original
message should be processed. If putData
returns a SIZE
of []
, then the message also ends, but with an exception thrown to the
caller of RequestMessage.send
.
If the consumer for a part was specified as a function handle rather than a
ContentConsumer
instance, then the function is called only the first time
the consumer is needed, and subsequently the same consumer instance is used for any
appropriate parts of the same response message. For parts processed by a function handle,
the corresponding ResponseMessage
in Response.Body.Data
contains only a header for the part, because the function does not have access to the
ResponseMessage
body.
A delegated consumer can access this consumer and its properties through its
MyDelegator
property, though that is rarely necessary.
Creation
Description
consumer = MultipartConsumer(
constructs a types
,consumer
)MultipartConsumer
to handle the specified
types
using the corresponding consumer
. You
can specify several argument pairs in any order as
types1,consumer1,...,typesN,consumerN
. MATLAB® searches the types
in the order they appear and uses
the first match. If there are no matches among the specified types, MATLAB uses the default set of consumers, depending on the type.
Input Arguments
Properties
Methods
More About
Version History
Introduced in R2018a
See Also
ResponseMessage
| RequestMessage
| GenericConsumer
| FileConsumer
| ImageConsumer
| MediaType
| MessageBody
| MultipartProvider