Documentation
¶
Overview ¶
Package soap provides transport-neutral SOAP 1.1 and SOAP 1.2 envelope, body, and fault primitives while preserving access to the original XML.
Use Parse/ParseReader for the SOAP 1.1 Note (2000-05-08) or SOAP 1.2 Part 1 Second Edition (2007-04-27), then DecodeBody or inspect a FaultError. Envelope raw accessors copy bytes; exported fault fields remain mutable. Raw fragment well-formedness is not schema/header-role processing, WS-Security or signing. Callbacks/readers are borrowed and cannot be cancelled through this API; no HTTP client, handle closing, cgo or background workers are owned here.
Index ¶
- Constants
- Variables
- func Encode(version Version, header, body any, options EncodeOptions) ([]byte, error)
- func EncodeWriter(writer io.Writer, version Version, header, body any, options EncodeOptions) error
- func Marshal(version Version, header, body []byte) ([]byte, error)
- func MarshalFault(fault Fault) ([]byte, error)
- func MarshalFaultWithOptions(fault Fault, options MarshalOptions) ([]byte, error)
- func MarshalFaultWriter(writer io.Writer, fault Fault) error
- func MarshalFaultWriterWithOptions(writer io.Writer, fault Fault, options MarshalOptions) error
- func MarshalWithOptions(version Version, header, body []byte, options MarshalOptions) ([]byte, error)
- func MarshalWriter(writer io.Writer, version Version, header, body []byte) error
- func MarshalWriterWithOptions(writer io.Writer, version Version, header, body []byte, options MarshalOptions) error
- type EncodeOptions
- type Envelope
- type Fault
- type FaultError
- type FaultReason
- type MarshalOptions
- type ParseOptions
- type Version
Constants ¶
const DefaultMaxBytes int64 = 1 << 20
DefaultMaxBytes is the default maximum SOAP envelope size.
Variables ¶
var ErrPayloadTooLarge = errors.New("payload exceeds size limit")
ErrPayloadTooLarge identifies SOAP output that exceeds the configured limit.
Functions ¶
func Encode ¶
func Encode(version Version, header, body any, options EncodeOptions) ([]byte, error)
Encode serializes typed header and body values as XML and wraps them in a SOAP envelope. A nil header is omitted and a nil body emits an empty Body.
func EncodeWriter ¶
EncodeWriter serializes typed SOAP values and writes the complete envelope to writer.
func Marshal ¶
Marshal creates a deterministic SOAP envelope around validated raw header and body fragments.
func MarshalFault ¶
MarshalFault validates and serializes a SOAP fault envelope.
func MarshalFaultWithOptions ¶
func MarshalFaultWithOptions(fault Fault, options MarshalOptions) ([]byte, error)
MarshalFaultWithOptions checks version, required code/reasons and Detail XML, then emits an owned size-bounded envelope. It escapes typed text but does not resolve lexical code prefixes or validate a SOAP schema. Stable input is borrowed; recursive subcode work and fragment prework are not heap/time quotas.
func MarshalFaultWriter ¶
MarshalFaultWriter serializes a SOAP fault and writes the complete envelope to writer.
func MarshalFaultWriterWithOptions ¶
func MarshalFaultWriterWithOptions(writer io.Writer, fault Fault, options MarshalOptions) error
MarshalFaultWriterWithOptions serializes a size-bounded SOAP fault and writes it only after serialization succeeds.
func MarshalWithOptions ¶
func MarshalWithOptions(version Version, header, body []byte, options MarshalOptions) ([]byte, error)
MarshalWithOptions borrows stable fragments, checks their XML syntax under a wrapper namespace, and emits a fresh envelope within the complete output quota. Empty header is omitted; empty body is allowed. It does not enforce Parse depth, single-body-child, schema or header-role rules, nor canonical XML. No payload is returned on error; fragment copies precede final output admission.
func MarshalWriter ¶
MarshalWriter creates a SOAP envelope around raw fragments and writes it to writer.
func MarshalWriterWithOptions ¶
func MarshalWriterWithOptions(writer io.Writer, version Version, header, body []byte, options MarshalOptions) error
MarshalWriterWithOptions creates a size-bounded SOAP envelope and writes it to writer only after serialization succeeds.
Types ¶
type EncodeOptions ¶
type EncodeOptions struct {
// MaxBytes caps returned encoded bytes; zero selects DefaultMaxBytes; negative values fail.
MaxBytes int64
// Indent selects indentation of typed header/body fragments, not envelope
// canonicalization.
Indent string
}
EncodeOptions controls XML serialization for typed SOAP header and body values.
type Envelope ¶
type Envelope struct {
// Version identifies the parsed/emitted SOAP namespace; zero is not a supported version.
Version Version
// Fault contains a parsed fault, if present; FaultError copies the struct shallowly, so
// slices alias the envelope fault.
Fault *Fault
// contains filtered or unexported fields
}
Envelope retains parsed SOAP structure and owned raw bytes. Construct it with Parse rather than the zero value; methods require a non-nil receiver. Exported Version/Fault remain mutable, so synchronize shared use and do not change the parsed version before DecodeBody. FaultError shares nested fault slices.
func Parse ¶
func Parse(payload []byte, options ParseOptions) (*Envelope, error)
Parse borrows payload until return and extracts SOAP structure. Valid faults return both the envelope and a *FaultError; other classified errors return nil. RawXML preserves the original source. Captured Header, Body and Fault XML retain lexical bytes from the decoder's UTF-8 stream after charset conversion, without re-encoding markup or adding inherited namespaces. MaxBytes caps raw input, not custom callback expansion. Custom callbacks are borrowed and own their output/work bounds; no context, schema or header-role processing is owned.
func ParseReader ¶
func ParseReader(reader io.Reader, options ParseOptions) (*Envelope, error)
ParseReader reads a bounded stream and parses a SOAP envelope.
func (*Envelope) BodyXML ¶
BodyXML returns a copy of lexical Body content after UTF-8 charset conversion. It does not add inherited namespaces.
func (*Envelope) DecodeBody ¶
DecodeBody reparses owned raw XML so the child retains inherited namespace bindings. A fault is returned before target validation. A non-nil pointer target is required, and it can be mutated before a later child/count/type failure; discard it on error. Nil receivers panic and custom codecs are borrowed.
type Fault ¶
type Fault struct {
// Version identifies the parsed/emitted SOAP namespace; zero is not a supported version.
Version Version
// Code retains lexical fault-code text, not an expanded QName or resolved namespace.
Code string
// Subcodes contains SOAP 1.2 lexical subcodes in nesting order.
Subcodes []string
// Reason is the SOAP 1.1 reason or first parsed SOAP 1.2 reason; it is sensitive
// diagnostic text.
Reason string
// Reasons contains SOAP 1.2 localized reasons; MarshalFault prefers it over Reason when
// nonempty.
Reasons []FaultReason
// Actor contains the optional SOAP 1.1 actor; empty omits it during marshaling.
Actor string
// Node contains the optional SOAP 1.2 node; empty omits it during marshaling.
Node string
// Role contains the optional SOAP 1.2 role; empty omits it during marshaling.
Role string
// Detail contains mutable UTF-8 inner fault XML, validated as a fragment when marshaled.
Detail []byte
// Raw contains mutable captured UTF-8 fault XML and is not replayed by MarshalFault.
Raw []byte
}
Fault is a mutable version-neutral SOAP 1.1/1.2 projection. Codes remain lexical, reasons can disclose peer data, and Raw/Detail are not standalone namespace snapshots. MarshalFault interprets fields for Version rather than replaying Raw.
type FaultError ¶
type FaultError struct {
// Fault contains a parsed fault, if present; FaultError copies the struct shallowly, so
// slices alias the envelope fault.
Fault Fault
}
FaultError reports a valid SOAP fault response.
func (*FaultError) Error ¶
func (e *FaultError) Error() string
Error returns the fixed fault category without disclosing fault fields.
func (*FaultError) Unwrap ¶
func (e *FaultError) Unwrap() error
Unwrap exposes the shared SOAP-fault classification.
type FaultReason ¶
type FaultReason struct {
// Language retains the SOAP 1.2 reason xml:lang value; empty does not negotiate a
// language.
Language string
// Text contains reason text, trimmed when parsed and escaped when emitted.
Text string
}
FaultReason is one localized SOAP 1.2 fault reason.
type MarshalOptions ¶
type MarshalOptions struct {
// MaxBytes caps returned encoded bytes; zero selects DefaultMaxBytes; negative values fail.
MaxBytes int64
}
MarshalOptions controls raw SOAP envelope and fault serialization.
type ParseOptions ¶
type ParseOptions struct {
// MaxBytes caps supplied input bytes; zero selects DefaultMaxBytes; negative values fail.
MaxBytes int64
// MaxDepth caps parsed XML element depth; zero selects xmlwire.DefaultMaxDepth; negative
// values fail.
MaxDepth int
// CharsetReader is a borrowed conversion callback used by independent XML passes. Nil uses
// xmlwire charset admission; it provides no context/deadline API.
CharsetReader func(string, io.Reader) (io.Reader, error)
}
ParseOptions controls SOAP envelope parsing.