Tag:ResponseWriter

  • Solve a problem with responsewriter in golang

    Time:2021-12-5

    When using the three methods set / writeheader / write in context.responsewriter, the order of use must be as follows, otherwise a setting will not take effect. ctx.ResponseWriter.Header().Set(“Content-type”, “application/text”) ctx.ResponseWriter.WriteHeader(403) ctx.ResponseWriter.Write([]byte(resp)) As shown in Figure 1: ctx.ResponseWriter.Header().Set(“Content-type”, “application/text”) ctx.ResponseWriter.Write([]byte(resp)) ctx.ResponseWriter.WriteHeader(403) It will cause the return code to be 200 all the time Supplement: in go, […]