Skip to content

Commit e64c8f2

Browse files
medclSteveLauC
andauthored
feat: support array for _ctx.response.body_json (#41)
* fix: remove duplicate name in tpl * chore: update loadgen-dsl WASM file --------- Co-authored-by: Steve Lau <[email protected]>
1 parent 28457c6 commit e64c8f2

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

loader.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,16 @@ func buildCtx(resp *fasthttp.Response, respBody []byte, duration time.Duration)
274274
"elapsed": int64(duration / time.Millisecond),
275275
},
276276
}
277+
278+
bodyJsonArray := []map[string]interface{}{}
279+
jsonErr := json.Unmarshal(respBody, &bodyJsonArray)
280+
if jsonErr == nil && len(bodyJsonArray) > 0 {
281+
event.Put("_ctx.response.body_json", bodyJsonArray)
282+
return event
283+
}
284+
277285
bodyJson := map[string]interface{}{}
278-
jsonErr := json.Unmarshal(respBody, &bodyJson)
286+
jsonErr = json.Unmarshal(respBody, &bodyJson)
279287
if jsonErr == nil {
280288
event.Put("_ctx.response.body_json", bodyJson)
281289
}

plugins/loadgen_dsl.wasm

-6.61 KB
Binary file not shown.

0 commit comments

Comments
 (0)