func DeleteXML(target string, body interface{}, headersQueryParams ...interface{}) *http.Request {
	req, err := newXMLRequest(http.MethodDelete, target, body, headersQueryParams...)
	if err != nil {
		panic(err)
	}
	return req
}
DeleteXML creates a HTTP DELETE with body marshaled to
XML. "Content-Type" header is automatically set to
"application/xml". It is a shortcut for:

tdhttp.NewXMLRequest(http.MethodDelete, target, body, headersQueryParams...)

See NewRequest for all possible formats accepted in headersQueryParams.
package tdhttp
import (
	"bytes"
	"encoding/base64"
	"encoding/json"
	"encoding/xml"
	"errors"
	"io"
	"net/http"
	"net/http/httptest"
	"net/url"
	"strings"
	"github.com/maxatome/go-testdeep/internal/color"
	"github.com/maxatome/go-testdeep/internal/flat"
	"github.com/maxatome/go-testdeep/internal/types"
)
func newRequest(method string, target string, body io.Reader, headersQueryParams []interface{}) (*http.Request, error) {
	header := http.Header{}
	qp := url.Values{}
	var cookies []*http.Cookie
	headersQueryParams = flat.Interfaces(headersQueryParams...)
	for i := 0; i < len(headersQueryParams); i++ {
		switch cur := headersQueryParams[i].(type) {
		case string:
			i++
			var val string
			if i < len(headersQueryParams) {
				var ok bool
				if val, ok = headersQueryParams[i].(string); !ok {
					return nil, errors.New(color.Bad(
						`header "%s" should have a string value, not a %T (@ headersQueryParams[%d])`,
						cur, headersQueryParams[i], i))
				}
			}
			header.Add(cur, val)
		case http.Header:
			for k, v := range cur {
				k = http.CanonicalHeaderKey(k)
				header[k] = append(header[k], v...)
			}
		case *http.Cookie:
			cookies = append(cookies, cur)
		case http.Cookie:
			cookies = append(cookies, &cur)
		case url.Values:
			for k, v := range cur {
				qp[k] = append(qp[k], v...)
			}
		case Q:
			err := cur.AddTo(qp)
			if err != nil {
				return nil, errors.New(color.Bad(
					"headersQueryParams... tdhttp.Q bad parameter: %s (@ headersQueryParams[%d])",
					err, i))
			}
		default:
			return nil, errors.New(color.Bad(
				"headersQueryParams... can only contains string, http.Header, http.Cookie, url.Values and tdhttp.Q, not %T (@ headersQueryParams[%d])",
				cur, i))
		}
	}
	u, err := url.Parse(target)
	if err != nil {
		return nil, errors.New(color.Bad("target is not a valid path: %s", err))
	}
	if len(qp) > 0 {
		if u.RawQuery != "" {
			u.RawQuery += "&"
		}
		u.RawQuery += qp.Encode()
		target = u.String()
	}
	req := httptest.NewRequest(method, target, body)
	for k, v := range header {
		req.Header[k] = append(req.Header[k], v...)
	}
	for _, c := range cookies {
		req.AddCookie(c)
	}
	return req, nil
}
func BasicAuthHeader(user, password string) http.Header {
	return http.Header{
		"Authorization": []string{
			"Basic " + base64.StdEncoding.EncodeToString([]byte(user+":"+password)),
		},
	}
}
func get(target string, headersQueryParams ...interface{}) (*http.Request, error) {
	return newRequest(http.MethodGet, target, nil, headersQueryParams)
}
func head(target string, headersQueryParams ...interface{}) (*http.Request, error) {
	return newRequest(http.MethodHead, target, nil, headersQueryParams)
}
func post(target string, body io.Reader, headersQueryParams ...interface{}) (*http.Request, error) {
	return newRequest(http.MethodPost, target, body, headersQueryParams)
}
func postForm(target string, data url.Values, headersQueryParams ...interface{}) (*http.Request, error) {
	return newRequest(
		http.MethodPost, target, strings.NewReader(data.Encode()),
		append(headersQueryParams, "Content-Type", "application/x-www-form-urlencoded"),
	)
}
func postMultipartFormData(target string, data *MultipartBody, headersQueryParams ...interface{}) (*http.Request, error) {
	return newRequest(
		http.MethodPost, target, data,
		append(headersQueryParams, "Content-Type", data.ContentType()),
	)
}
func put(target string, body io.Reader, headersQueryParams ...interface{}) (*http.Request, error) {
	return newRequest(http.MethodPut, target, body, headersQueryParams)
}
func patch(target string, body io.Reader, headersQueryParams ...interface{}) (*http.Request, error) {
	return newRequest(http.MethodPatch, target, body, headersQueryParams)
}
func del(target string, body io.Reader, headersQueryParams ...interface{}) (*http.Request, error) {
	return newRequest(http.MethodDelete, target, body, headersQueryParams)
}
func NewRequest(method, target string, body io.Reader, headersQueryParams ...interface{}) *http.Request {
	req, err := newRequest(method, target, body, headersQueryParams)
	if err != nil {
		panic(err)
	}
	return req
}
func Get(target string, headersQueryParams ...interface{}) *http.Request {
	req, err := get(target, headersQueryParams...)
	if err != nil {
		panic(err)
	}
	return req
}
func Head(target string, headersQueryParams ...interface{}) *http.Request {
	req, err := head(target, headersQueryParams...)
	if err != nil {
		panic(err)
	}
	return req
}
func Post(target string, body io.Reader, headersQueryParams ...interface{}) *http.Request {
	req, err := post(target, body, headersQueryParams...)
	if err != nil {
		panic(err)
	}
	return req
}
func PostForm(target string, data url.Values, headersQueryParams ...interface{}) *http.Request {
	req, err := postForm(target, data, headersQueryParams...)
	if err != nil {
		panic(err)
	}
	return req
}
func PostMultipartFormData(target string, data *MultipartBody, headersQueryParams ...interface{}) *http.Request {
	req, err := postMultipartFormData(target, data, headersQueryParams...)
	if err != nil {
		panic(err)
	}
	return req
}
func Put(target string, body io.Reader, headersQueryParams ...interface{}) *http.Request {
	req, err := put(target, body, headersQueryParams...)
	if err != nil {
		panic(err)
	}
	return req
}
func Patch(target string, body io.Reader, headersQueryParams ...interface{}) *http.Request {
	req, err := patch(target, body, headersQueryParams...)
	if err != nil {
		panic(err)
	}
	return req
}
func Delete(target string, body io.Reader, headersQueryParams ...interface{}) *http.Request {
	req, err := del(target, body, headersQueryParams...)
	if err != nil {
		panic(err)
	}
	return req
}
func newJSONRequest(method, target string, body interface{}, headersQueryParams ...interface{}) (*http.Request, error) {
	b, err := json.Marshal(body)
	if err != nil {
		if opErr, ok := types.AsOperatorNotJSONMarshallableError(err); ok {
			var plus string
			switch op := opErr.Operator(); op {
			case "JSON", "SubJSONOf", "SuperJSONOf":
				plus = ", use json.RawMessage() instead"
			}
			return nil, errors.New(color.Bad("JSON encoding failed: %s%s", err, plus))
		}
		return nil, errors.New(color.Bad("%s", err))
	}
	return newRequest(
		method, target, bytes.NewReader(b),
		append(headersQueryParams, "Content-Type", "application/json"),
	)
}
func NewJSONRequest(method, target string, body interface{}, headersQueryParams ...interface{}) *http.Request {
	req, err := newJSONRequest(method, target, body, headersQueryParams...)
	if err != nil {
		panic(err)
	}
	return req
}
func PostJSON(target string, body interface{}, headersQueryParams ...interface{}) *http.Request {
	req, err := newJSONRequest(http.MethodPost, target, body, headersQueryParams...)
	if err != nil {
		panic(err)
	}
	return req
}
func PutJSON(target string, body interface{}, headersQueryParams ...interface{}) *http.Request {
	req, err := newJSONRequest(http.MethodPut, target, body, headersQueryParams...)
	if err != nil {
		panic(err)
	}
	return req
}
func PatchJSON(target string, body interface{}, headersQueryParams ...interface{}) *http.Request {
	req, err := newJSONRequest(http.MethodPatch, target, body, headersQueryParams...)
	if err != nil {
		panic(err)
	}
	return req
}
func DeleteJSON(target string, body interface{}, headersQueryParams ...interface{}) *http.Request {
	req, err := newJSONRequest(http.MethodDelete, target, body, headersQueryParams...)
	if err != nil {
		panic(err)
	}
	return req
}
func newXMLRequest(method, target string, body interface{}, headersQueryParams ...interface{}) (*http.Request, error) {
	b, err := xml.Marshal(body)
	if err != nil {
		return nil, errors.New(color.Bad("XML encoding failed: %s", err))
	}
	return newRequest(
		method, target, bytes.NewReader(b),
		append(headersQueryParams, "Content-Type", "application/xml"),
	)
}
func NewXMLRequest(method, target string, body interface{}, headersQueryParams ...interface{}) *http.Request {
	req, err := newXMLRequest(method, target, body, headersQueryParams...)
	if err != nil {
		panic(err)
	}
	return req
}
func PostXML(target string, body interface{}, headersQueryParams ...interface{}) *http.Request {
	req, err := newXMLRequest(http.MethodPost, target, body, headersQueryParams...)
	if err != nil {
		panic(err)
	}
	return req
}
func PutXML(target string, body interface{}, headersQueryParams ...interface{}) *http.Request {
	req, err := newXMLRequest(http.MethodPut, target, body, headersQueryParams...)
	if err != nil {
		panic(err)
	}
	return req
}
func PatchXML(target string, body interface{}, headersQueryParams ...interface{}) *http.Request {
	req, err := newXMLRequest(http.MethodPatch, target, body, headersQueryParams...)
	if err != nil {
		panic(err)
	}
	return req
}