@@ -141,48 +141,49 @@ func (m *HTTPTampererSymptom) MuckRequest(ctx *muxy.Context) {
141141
142142// MuckResponse adds chaos to the response
143143func (m * HTTPTampererSymptom ) MuckResponse (ctx * muxy.Context ) {
144-
145- // Body
146- if m .Response .Body != "" {
147- cl := ioutil .NopCloser (bytes .NewReader ([]byte (m .Response .Body )))
148- r := & http.Response {
149- Request : ctx .Request ,
150- Header : ctx .Response .Header ,
151- Close : ctx .Response .Close ,
152- ContentLength : ctx .Response .ContentLength ,
153- Trailer : ctx .Response .Trailer ,
154- TLS : ctx .Response .TLS ,
155- TransferEncoding : ctx .Response .TransferEncoding ,
156- Status : ctx .Response .Status ,
157- StatusCode : ctx .Response .StatusCode ,
158- Proto : ctx .Response .Proto ,
159- ProtoMajor : ctx .Response .ProtoMajor ,
160- ProtoMinor : ctx .Response .ProtoMinor ,
161- Body : cl ,
144+ if ctx .Response != nil {
145+ // Body
146+ if m .Response .Body != "" {
147+ cl := ioutil .NopCloser (bytes .NewReader ([]byte (m .Response .Body )))
148+ r := & http.Response {
149+ Request : ctx .Request ,
150+ Header : ctx .Response .Header ,
151+ Close : ctx .Response .Close ,
152+ ContentLength : ctx .Response .ContentLength ,
153+ Trailer : ctx .Response .Trailer ,
154+ TLS : ctx .Response .TLS ,
155+ TransferEncoding : ctx .Response .TransferEncoding ,
156+ Status : ctx .Response .Status ,
157+ StatusCode : ctx .Response .StatusCode ,
158+ Proto : ctx .Response .Proto ,
159+ ProtoMajor : ctx .Response .ProtoMajor ,
160+ ProtoMinor : ctx .Response .ProtoMinor ,
161+ Body : cl ,
162+ }
163+ log .Debug ("HTTP Tamperer Injecting HTTP Response Body with [%s]" , log .Colorize (log .BLUE , m .Response .Body ))
164+ * ctx .Response = * r
162165 }
163- log .Debug ("HTTP Tamperer Injecting HTTP Response Body with [%s]" , log .Colorize (log .BLUE , m .Response .Body ))
164- * ctx .Response = * r
165- }
166166
167- // Set Cookies
168- for _ , c := range m .Response .Cookies {
169- c .Expires = stringToDate (c .RawExpires )
170- log .Debug ("HTTP Tamperer Spoofing Response Cookie [%s => %s]" , log .Colorize (log .LIGHTMAGENTA , c .Name ), c .String ())
171- ctx .Response .Header .Add ("Set-Cookie" , c .String ())
172- }
167+ // Set Cookies
168+ for _ , c := range m .Response .Cookies {
169+ c .Expires = stringToDate (c .RawExpires )
170+ log .Debug ("HTTP Tamperer Spoofing Response Cookie [%s => %s]" , log .Colorize (log .LIGHTMAGENTA , c .Name ), c .String ())
171+ ctx .Response .Header .Add ("Set-Cookie" , c .String ())
172+ }
173173
174- // Set Headers
175- for k , v := range m .Response .Headers {
176- key := strings .ToTitle (strings .Replace (k , "_" , "-" , - 1 ))
177- log .Debug ("HTTP Tamperer Spoofing Response Header [%s => %s]" , log .Colorize (log .LIGHTMAGENTA , key ), v )
178- ctx .Response .Header .Add (key , v )
179- }
174+ // Set Headers
175+ for k , v := range m .Response .Headers {
176+ key := strings .ToTitle (strings .Replace (k , "_" , "-" , - 1 ))
177+ log .Debug ("HTTP Tamperer Spoofing Response Header [%s => %s]" , log .Colorize (log .LIGHTMAGENTA , key ), v )
178+ ctx .Response .Header .Add (key , v )
179+ }
180180
181- // This Writes all headers, setting status code - so call this last
182- if m .Response .Status != 0 {
183- log .Debug ("HTTP Tamperer Spoofing Response Code From [%d] to [%s]" , ctx .Response .StatusCode , log .Colorize (log .LIGHTMAGENTA , fmt .Sprintf ("%d" , m .Response .Status )))
184- ctx .Response .StatusCode = m .Response .Status
185- ctx .Response .Status = http .StatusText (m .Response .Status )
181+ // This Writes all headers, setting status code - so call this last
182+ if m .Response .Status != 0 {
183+ log .Debug ("HTTP Tamperer Spoofing Response Code From [%d] to [%s]" , ctx .Response .StatusCode , log .Colorize (log .LIGHTMAGENTA , fmt .Sprintf ("%d" , m .Response .Status )))
184+ ctx .Response .StatusCode = m .Response .Status
185+ ctx .Response .Status = http .StatusText (m .Response .Status )
186+ }
186187 }
187188}
188189
0 commit comments