From 3186505aefd0d083213c7c98726ef460c652551d Mon Sep 17 00:00:00 2001 From: Jan Halfar Date: Tue, 16 Feb 2016 08:36:49 +0100 Subject: [PATCH] dryed up sending content length in soap responses --- server.go | 8 ++++---- soap.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/server.go b/server.go index 88aeeb8..3bd560f 100644 --- a/server.go +++ b/server.go @@ -84,13 +84,14 @@ func (s *Server) handleError(err error, w http.ResponseWriter) { w.WriteHeader(http.StatusInternalServerError) w.Write([]byte("could not marshal soap fault for: " + err.Error() + " xmlError: " + xmlErr.Error())) } else { - sendSOAPHeader(w) + sendSOAPHeader(w, len(xmlBytes)) w.Write(xmlBytes) } } -func sendSOAPHeader(w http.ResponseWriter) { +func sendSOAPHeader(w http.ResponseWriter, contentLength int) { w.Header().Add("Content-Type", SOAPContentType) + w.Header().Add("Content-Length", fmt.Sprint(contentLength)) } func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { @@ -169,8 +170,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { if err != nil { s.handleError(errors.New("could not marshal response:: "+err.Error()), w) } - sendSOAPHeader(w) - w.Header().Set("Content-Length", fmt.Sprint(len(xmlBytes))) + sendSOAPHeader(w, len(xmlBytes)) w.Write(xmlBytes) } else { l("action handler sent its own output") diff --git a/soap.go b/soap.go index 54d5103..a644b80 100644 --- a/soap.go +++ b/soap.go @@ -5,7 +5,7 @@ import ( "log" ) -//var SOAPContentType = "application/soap+xml; charset=\"utf-8\"" +// SOAPContentType configurable soap content type var SOAPContentType = "text/xml; charset=\"utf-8\"" // Verbose be verbose