Main Content

complete

Class:matlab.net.http.io.ContentProvider
Package:matlab.net.http.io

Complete HTTP header for ContentProvider

Syntax

complete(provider,URI)

Description

complete(provider,URI)augments the header of the message with header fields required by this provider. TheRequestMessage.sendandRequestMessage.completemethods call this method before validating the header or adding any default fields, and before calling other methods in this class except forexpectedContentLength.

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

TheRequestMessage如果消息已经完成,方法不调用此方法(也就是说RequestMessage.Completedistrue). However, a subsequent change to the message after completion resets theRequestMessage.Completedproperty, allowing those methods to invoke this method again. Therefore, providers should be prepared for more than one call tocompletebefore a call tostart. Oncestarthas been called, MATLAB®does not reinvokecompletein this provider unlessreusablereturnstrueto indicate that this provider can be reused for another message.

AContentProviderthat extends anotherContentProvidershould first call its superclasscompletemethod to add header fields toHeaderthat 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 inexpectedContentLength或插入一个Content-Lengt实现这个方法h field in theHeader.

此方法未在带有一个的消息上调用完全的property set totrue, 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 thestartmethod.

Input Arguments

expand all

Content provider, specified as amatlab.net.http.io.ContentProviderobject.

Uniform resource identifier, specified as amatlab.net.URIobject.

Attributes

Access protected

Examples

expand all

The following is a coding pattern for aContentProviderthat extends aSuperclassProviderand adds theHeaderFieldmyField.

functioncomplete(obj, uri) complete@SuperclassProvider(obj, uri); field = obj.Header.getFields('My-Field');ifisempty(field) myField = HeaderField('My-Field', value); obj.Header = obj.Header.addFields(myField);end

Version History

Introduced in R2018a