improved http header handling, exposed new method on server WriteHeader

This commit is contained in:
Florian Schlegel 2016-12-01 17:19:24 +01:00
parent 520c809155
commit dd9aa50d0a
2 changed files with 17 additions and 6 deletions

View File

@ -94,15 +94,16 @@ func (c *Client) Call(soapAction string, request, response interface{}) (httpRes
envelope.Body.Content = request
xmlBytes, err := c.Marshaller.Marshal(envelope)
if err != nil {
return nil, err
}
// Adjust namespaces for SOAP 1.2
if c.SoapVersion == SoapVersion12 {
tmp := string(xmlBytes)
tmp = strings.Replace(tmp, NamespaceSoap11, NamespaceSoap12, -1)
xmlBytes = []byte(tmp)
}
if err != nil {
return nil, err
}
//log.Println(string(xmlBytes))
//l("SOAP Client Call() => Marshalled Request\n", string(xmlBytes))
@ -185,7 +186,7 @@ func (c *Client) Call(soapAction string, request, response interface{}) (httpRes
l("This is not a SOAP-Message: \n" + string(rawbody))
return nil, errors.New("This is not a SOAP-Message: \n" + string(rawbody))
}
l("RAWBODY\n", string(rawbody))
}
// We have an empty body or a SOAP body

View File

@ -108,9 +108,19 @@ func (s *Server) handleError(err error, w http.ResponseWriter) {
}
}
// WriteHeader first sets header like content-type and then writes the header
func (s *Server) WriteHeader(w http.ResponseWriter, code int) {
setContentType(w, s.ContentType)
w.WriteHeader(code)
}
func setContentType(w http.ResponseWriter, contentType string) {
w.Header().Set("Content-Type", contentType)
}
func addSOAPHeader(w http.ResponseWriter, contentLength int, contentType string) {
w.Header().Add("Content-Type", contentType)
w.Header().Add("Content-Length", fmt.Sprint(contentLength))
setContentType(w, contentType)
w.Header().Set("Content-Length", fmt.Sprint(contentLength))
}
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {