服务相关流量统计增加Header

This commit is contained in:
GoEdgeLab
2022-03-26 12:29:34 +08:00
parent 597b18f493
commit bcaa1426b0
4 changed files with 25 additions and 6 deletions

View File

@@ -58,8 +58,9 @@ type HTTPWriter struct {
size int64
statusCode int
sentBodyBytes int64
statusCode int
sentBodyBytes int64
sentHeaderBytes int64
isOk bool // 是否完全成功
isFinished bool // 是否已完成
@@ -692,6 +693,23 @@ func (this *HTTPWriter) SentBodyBytes() int64 {
return this.sentBodyBytes
}
// SentHeaderBytes 计算发送的Header字节数
func (this *HTTPWriter) SentHeaderBytes() int64 {
if this.sentHeaderBytes > 0 {
return this.sentHeaderBytes
}
for k, v := range this.Header() {
for _, v1 := range v {
this.sentHeaderBytes += int64(len(k) + 2 + len(v1) + 1)
}
}
return this.sentHeaderBytes
}
func (this *HTTPWriter) SetSentHeaderBytes(sentHeaderBytes int64) {
this.sentHeaderBytes = sentHeaderBytes
}
// WriteHeader 写入状态码
func (this *HTTPWriter) WriteHeader(statusCode int) {
if this.rawWriter != nil {