123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package xhttp
- import (
- "encoding/json"
- "encoding/xml"
- "net/http"
- "net/url"
- )
- // Message HTTP response
- type Message struct {
- req *http.Request
- res *http.Response
- StatusCode int
- Body []byte
- Header http.Header
- }
- // JSON Body to JSON
- func (m Message) JSON(v interface{}) error {
- return json.Unmarshal(m.Body, v)
- }
- // XML Body to XML
- func (m Message) XML(v interface{}) error {
- return xml.Unmarshal(m.Body, v)
- }
- // Cookies parses and returns the cookies set in the Set-Cookie headers.
- func (m Message) Cookies() []*http.Cookie {
- return m.res.Cookies()
- }
- // Location returns the URL of the response's "Location" header, if present. Relative redirects are resolved relative to the Response's Request. ErrNoLocation is returned if no Location header is present.
- func (m Message) Location() (*url.URL, error) {
- return m.res.Location()
- }
- // UserAgent returns the client's User-Agent, if sent in the request.
- func (m Message) UserAgent() string {
- return m.req.UserAgent()
- }
- // Referer returns the referring URL, if sent in the request.
- func (m Message) Referer() string {
- return m.req.Referer()
- }
|