XEP-0138: Stream Compression

This document defines an XMPP protocol extension for negotiating compression of XML streams, especially in situations where standard TLS compression cannot be negotiated. The protocol provides a modular framework that can accommodate a wide range of compression algorithms; the ZLIB compression algorithm is mandatory-to-implement, but implementations may support other algorithms in addition.
  • Joe Hildebrand
  • Peter Saint-Andre
© 1999 – 2020 XMPP Standards Foundation. SEE LEGAL NOTICES.


Standards Track
2.0 (2009-05-27)
Document Lifecycle
  1. Experimental
  2. Proposed
  3. Draft
  4. Final

1. Introduction

XMPP Core [1] specifies the use of Transport Layer Security (TLS; see RFC 5246 [2]) for encryption of XML streams, and TLS includes the ability to compress encrypted traffic (see RFC 3749 [3]). However, not all computing platforms are able to implement TLS, and traffic compression may be desirable for communication by applications on such computing platforms. This document defines a mechanism for negotiating the compression of XML streams outside the context of TLS.

2. Use Case

The protocol flow is as follows:

Example 1. Receiving Entity Offers Stream Compression Feature
  <starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>

Note: The <compression/> element MUST contain at least one <method/> child element. Each <method/> element MUST contain XML character data that specifies the name of a compression method, and such method names SHOULD be registered as described in the Compression Methods Registry section of this document. The methods SHOULD be provided in order of preference.

The initiating entity then MAY request compression by specifying one of the methods advertised by the receiving entity:

Example 2. Initiating Entity Requests Stream Compression

Note: If the initiating entity did not understand any of the advertised compression methods, it SHOULD ignore the compression option and proceed as if no compression methods were advertised.

If the initiating entity requests a stream compression method that is not supported by the receiving entity, the receiving entity MUST return an <unsupported-method/> error:

Example 3. Receiving Entity Reports That Method is Unsupported
<failure xmlns='http://jabber.org/protocol/compress'>

If the receiving entity finds the requested method unacceptable or unworkable for any other reason, it MUST return a <setup-failed/> error:

Example 4. Receiving Entity Reports That Negotiation of Stream Compression Failed

Note: Failure of the negotiation SHOULD NOT be treated as an unrecoverable error and therefore SHOULD NOT result in a stream error. In particular, the initiating entity is free to retry the compression negotiation if it fails.

If no error occurs, the receiving entity MUST inform the initiating entity that compression has been successfully negotiated:

Example 5. Receiving Entity Acknowledges Negotiation of Stream Compression
<compressed xmlns='http://jabber.org/protocol/compress'/>

Both entities MUST now consider the previous (uncompressed) stream to be null and void, just as with TLS negotiation and SASL negotiation (as specified in RFC 3920) and MUST begin compressed communications with a new (compressed) stream. Therefore the initiating entity MUST initiate a new stream to the receiving entity:

Example 6. Initiating Entity Initiates New (Compressed) Stream

If compression processing fails after the new (compressed) stream has been established, the entity that detects the error SHOULD generate a stream error and close the stream:

Example 7. Entity Closes Stream Because of a Processing Error

3. Business Rules

The following business rules apply:

For detailed recommendations regarding the order of stream feature negotiation, refer to Recommended Order of Stream Feature Negotiation (XEP-0170) [4].

4. Mandatory-to-Implement Technologies

Support for the ZLIB compression method as specified in RFC 1950 [5] is REQUIRED.

All other methods are OPTIONAL; such methods may be defined in future specifications or by registration as described in the Compression Methods Registry section of this document.

5. Optional Technologies

Implementations MAY support the following methods in addition to ZLIB:

6. Implementation Notes

When using ZLIB for compression, the sending application SHOULD complete a partial flush of ZLIB when its current send is complete. Note that this statement is deliberately somewhat vague: the sending application may end up performing this partial flush after sending every XML stanza, but on the other hand may perform the partial flush only after sending a group of stanzas that have been queued up for delivery. When to flush the state of the compression application is up to the sending application.

7. Security Considerations

Stream encryption via TLS (as defined in RFC 3920) and stream compression (as defined herein) are not mutually exclusive, but stream encryption via TLS MUST be negotiated before negotiation of stream compression in order to secure the stream.

Many of the security considerations related to TLS compression (see Section 6 of RFC 3749) also apply to stream compression.

8. IANA Considerations


9. XMPP Registrar Considerations

9.1 Stream Features

The XMPP Registrar [8] includes 'http://jabber.org/features/compress' in its registry of stream features.

9.2 Protocol Namespaces

The XMPP Registrar includes 'http://jabber.org/protocol/compress' in its registry of protocol namespaces.

9.3 Compression Methods Registry

The XMPP Registrar maintains a registry of compression methods at <https://xmpp.org/registrar/compress.html>.

9.3.1 Process


  <name>the XML character data of the method element</name>
  <desc>a natural-language description of the compression method</desc>
  <doc>the document that specifies or registers the compression method</doc>

The registrant may register more than one compression method at a time, each contained in a separate <method/> element.

9.3.2 Registration

  <desc>the ZLIB compression method</desc>
  <doc>RFC 1950</doc>

10. XML Schemas

10.1 Stream Feature



      The protocol documented by this schema is defined in
      XEP-0138: http://www.xmpp.org/extensions/xep-0138.html

  <xs:element name='compression'>
        <xs:element name='method' type='xs:NCName' maxOccurs='unbounded'/>


10.2 Protocol Namespace



      The protocol documented by this schema is defined in

  <xs:import namespace='urn:ietf:params:xml:ns:xmpp-stanzas'

  <xs:element name='compress'>
        <xs:element name='method' type='xs:NCName' minOccurs='1' maxOccurs='unbounded'/>

  <xs:element name='compressed' type='empty'/>

  <xs:element name='failure'>
        <xs:element name='setup-failed' type='empty'/>
        <xs:element name='processing-failed' type='empty'/>
        <xs:element name='unsupported-method' type='empty'/>
        <xs:sequence xmlns:err='urn:ietf:params:xml:ns:xmpp-stanzas'>
          <xs:group ref='err:stanzaErrorGroup'/>
          <xs:element ref='err:text' minOccurs='0'/>

  <xs:simpleType name='empty'>
    <xs:restriction base='xs:string'>
      <xs:enumeration value=''/>



Appendix A: Document Information

XMPP Standards Foundation
Standards Track
Last Updated
Approving Body
XMPP Council
Superseded By
Short Name
XML Schema for the 'compress' namespace: <http://www.xmpp.org/schemas/compress.xsd>
XML Schema for the 'feature' namespace: <http://www.xmpp.org/schemas/compress-feature.xsd>
Source Control

This document in other formats: XML  PDF

Appendix B: Author Information

Joe Hildebrand
Peter Saint-Andre





Disclaimer of Warranty


Limitation of Liability


IPR Conformance


Visual Presentation


Appendix D: Relation to XMPP


Appendix E: Discussion Venue



Errata can be sent to <editor@xmpp.org>.

Appendix F: Requirements Conformance


Appendix G: Notes



3. RFC 3749: Transport Layer Security Protocol Compression Methods <http://tools.ietf.org/html/rfc3749>.



6. XEP-0229: Stream Compression with LZW <https://xmpp.org/extensions/xep-0229.html>.



Appendix H: Revision History


  1. Version 2.0 (2009-05-27)

    Per a vote of the XMPP Council, advanced status to Final.

  2. Version 1.3 (2007-09-26)

    Moved specification of LZW algorithm to XEP-0229.

  3. Version 1.2 (2007-08-22)

    Clarified when compression shall be considered to start; per XEP-0170, specified that compression should be negotiated after SASL.

  4. Version 1.1 (2005-12-14)

    More completely specified error handling; mentioned LZW (DCLZ) method.

  5. Version 1.0 (2005-06-16)


  6. Version 0.5 (2005-05-18)

    Modifications to address Council feedback: used RFC 3920 terminology; specified error conditions; specified ZLIB as mandatory to implement.

  7. Version 0.4 (2005-05-11)

    Corrected several errors in the schemas.

  8. Version 0.3 (2005-03-28)

    Specified compression methods registry.

  9. Version 0.2 (2004-09-28)

    Fixed TLS text per list discussion.

  10. Version 0.1 (2004-07-16)

    Initial version.