我有一些測(cè)試將標(biāo)頭注入 Echo,如下所示:func test() { request := httptest.NewRequest(http.MethodGet, "/", http.NoBody) recorder := httptest.NewRecorder() recorder.HeaderMap.Add("If-None-Match", "\"d41d8cd98f00b204e9800998ecf8427e\"") context := inst.NewContext(request, recorder) testFunc(context) fmt.Printf("Status: %d", context.Response().Status)}func testFunc(ctx echo.Context) { ifNoneMatch := ctx.Response().Header().Get(headers.IfNoneMatch) if !util.IsEmpty(ifNoneMatch) && etag == ifNoneMatch { ctx.Response().WriteHeader(304) }}我當(dāng)前的解決方案有效,但由于HeaderMap已棄用,我正試圖找到一種更好的方法來(lái)執(zhí)行此操作。Result我試過(guò)通過(guò) doing注入標(biāo)頭,Result().Header.Add("If-None-Match", "\"d41d8cd98f00b204e9800998ecf8427e\"")但在調(diào)用context.Response().Header(). 有什么辦法嗎?
將標(biāo)頭注入 httptest.Recorder 以便 echo 上下文可以在
動(dòng)漫人物
2022-11-23 20:08:34