File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -104,13 +104,26 @@ func HttpTest(
104104 RequestHeaders : r .Header ,
105105 StatusCode : resp .StatusCode ,
106106 Headers : headers ,
107- BodyString : string (body ),
107+ BodyString : truncateAndStringifyBody (body ),
108108 Variables : variables ,
109109 }
110110 }
111111 return responses , finalBaseURL
112112}
113113
114+ // truncateAndStringifyBody
115+ // in some lessons we yeet the entire body up to the server, but we really shouldn't ever care
116+ // about more than 100,000 stringified characters of it, so this protects against giant bodies
117+ func truncateAndStringifyBody (body []byte ) string {
118+ bodyString := string (body )
119+ const maxBodyLength = 100000
120+ if len (bodyString ) > maxBodyLength {
121+ fmt .Printf ("truncating from %v to %v" , len (bodyString ), maxBodyLength )
122+ bodyString = bodyString [:maxBodyLength ]
123+ }
124+ return bodyString
125+ }
126+
114127func parseVariables (body []byte , vardefs []api.ResponseVariable , variables map [string ]string ) error {
115128 for _ , vardef := range vardefs {
116129 val , err := valFromJQPath (vardef .Path , string (body ))
Original file line number Diff line number Diff line change @@ -258,7 +258,7 @@ func prettyPrintHTTPTest(test api.HTTPTest, variables map[string]string) string
258258 }
259259 if test .BodyContains != nil {
260260 interpolated := checks .InterpolateVariables (* test .BodyContains , variables )
261- return fmt .Sprintf ("Expecting JSON body to contain: %s" , interpolated )
261+ return fmt .Sprintf ("Expecting body to contain: %s" , interpolated )
262262 }
263263 if test .BodyContainsNone != nil {
264264 interpolated := checks .InterpolateVariables (* test .BodyContainsNone , variables )
You can’t perform that action at this time.
0 commit comments