forked from alex-arce/gosoap
-
Notifications
You must be signed in to change notification settings - Fork 3
/
response.go
64 lines (51 loc) · 1.36 KB
/
response.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package soap
import (
"mime"
"net/http"
"strings"
"github.com/m29h/xml"
)
// Response contains the result of the request.
type Response struct {
*http.Response
body interface{}
fault *Fault
}
func newResponse(httpResp *http.Response, req *Request) *Response {
return &Response{
Response: httpResp,
body: req.resp,
}
}
// Body returns the SOAP body. The value comes from what was passed into the linked request.
func (r *Response) Body() interface{} {
return r.body
}
// Fault returns the SOAP fault encountered, if present
func (r *Response) Fault() *Fault {
return r.fault
}
func (r *Response) deserialize() error {
mediaType, mediaParams, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
if err != nil {
return err
}
envelope := NewEnvelope(r.body)
if strings.HasPrefix(mediaType, "multipart/") {
// Here we handle any SOAP requests embedded in a MIME multipart response.
err = newXopDecoder(r.Response.Body, mediaParams).decode(envelope)
} else if strings.Contains(mediaType, "text/xml") {
// This is normal SOAP XML response handling.
err = xml.NewDecoder(r.Response.Body).Decode(&envelope)
} else {
err = ErrUnsupportedContentType
}
if err != nil {
return err
}
// Propagate the changes from parsing the envelope to the response struct
if envelope.Body.Fault != nil {
r.fault = envelope.Body.Fault
}
return nil
}