1 Star 0 Fork 0

liujinsuo/tool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
toolhttp.go 855 Bytes
一键复制 编辑 原始数据 按行查看 历史
liujinsuo 提交于 2年前 . ResponseWriter
package main
import (
"fmt"
"gitee.com/liujinsuo/tool/toolhttp"
"net/http"
)
func main() {
httpt()
}
func httpm(handler http.Handler) http.Handler {
return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
fmt.Println(1)
w := toolhttp.NewResponseWriter(writer)
handler.ServeHTTP(w, request)
fmt.Println("body=", w.GetBody().String(), "code=", w.GetCode())
w.CleanBody() //清空响应body
w.Write([]byte("1111111")) //重写响应body
w.ResponseWriter.Write(w.GetBody().Bytes())
w.ResponseWriter.WriteHeader(w.GetCode())
})
}
func httpt() {
http.Handle("/", httpm(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
fmt.Println(2)
writer.WriteHeader(http.StatusOK)
writer.Write([]byte("2222222222"))
})))
http.ListenAndServe(":8080", http.DefaultServeMux)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/liujinsuo/tool.git
git@gitee.com:liujinsuo/tool.git
liujinsuo
tool
tool
086db71efc37

搜索帮助