Main Content



Complete HTTP header for ContentProvider




complete(provider,URI) augments the header of the message with header fields required by this provider. The RequestMessage.send and RequestMessage.complete methods call this method before validating the header or adding any default fields, and before calling other methods in this class except for expectedContentLength.

This is where subclasses can add any fields to Header that depend on the content, such as Content-Type. See the description of the Header property for more information.

The RequestMessage methods do not call this method if the message has already been completed (that is, if RequestMessage.Completed is true). However, a subsequent change to the message after completion resets the RequestMessage.Completed property, allowing those methods to invoke this method again. Therefore, providers should be prepared for more than one call to complete before a call to start. Once start has been called, MATLAB® does not reinvoke complete in this provider unless reusable returns true to indicate that this provider can be reused for another message.

A ContentProvider that extends another ContentProvider should first call its superclass complete method to add header fields to Header that the superclass needs, and then, on return, modify those fields if desired.

The default behavior of this method does nothing, but throws an exception if this provider has been started and is not reusable. Providers that override this method should always invoke their superclass.

If this provider is not a multipart delegate, and you want to include a Content-Length field in the message (thereby avoiding chunked transfer coding), then you should return a nonempty value in expectedContentLength or implement this method to insert a Content-Length field in the Header.

This method is not invoked on messages with a Completed property set to true, which generally means that this method is invoked only once per message, even if this message is resent multiple times. Implementations of this method should, therefore, perform any initialization that needs to be done only once per message. Costly initialization that does not need to be done until the data is ready to be sent should be performed in the start method.

Input Arguments

expand all

Content provider, specified as a object.

Uniform resource identifier, specified as a object.




expand all

The following is a coding pattern for a ContentProvider that extends a SuperclassProvider and adds the HeaderField myField.

function complete(obj, uri)
            complete@SuperclassProvider(obj, uri);
            field = obj.Header.getFields('My-Field');
            if isempty(field)
                myField = HeaderField('My-Field', value);
                obj.Header = obj.Header.addFields(myField);

Version History

Introduced in R2018a