From dd9aa50d0aa3085212b850d857629009f23fe2aa Mon Sep 17 00:00:00 2001 From: Florian Schlegel Date: Thu, 1 Dec 2016 17:19:24 +0100 Subject: [PATCH] improved http header handling, exposed new method on server WriteHeader --- client.go | 9 +++++---- server.go | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/client.go b/client.go index 5a9b151..98d1421 100644 --- a/client.go +++ b/client.go @@ -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 diff --git a/server.go b/server.go index 18dd391..7e4ad6d 100644 --- a/server.go +++ b/server.go @@ -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) {