Skip to content

Commit

Permalink
add log
Browse files Browse the repository at this point in the history
  • Loading branch information
li-jin-gou committed Jan 3, 2025
1 parent 5729635 commit 6f9797a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/protocol/http1/req/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"encoding/base64"
"errors"
"fmt"
"github.com/cloudwego/hertz/pkg/common/hlog"
"io"
"mime/multipart"

Expand Down Expand Up @@ -253,6 +254,7 @@ func write(req *protocol.Request, w network.Writer, usingProxy bool) error {
// then errBodyTooLarge is returned.
func ContinueReadBodyStream(req *protocol.Request, zr network.Reader, maxBodySize int, preParseMultipartForm ...bool) error {
var err error
hlog.Infof("Read stream req body contentLength = %d", req.Header.ContentLength())
contentLength := req.Header.ContentLength()
if contentLength > 0 {
if len(preParseMultipartForm) == 0 || preParseMultipartForm[0] {
Expand Down Expand Up @@ -287,6 +289,7 @@ func ContinueReadBodyStream(req *protocol.Request, zr network.Reader, maxBodySiz
bodyBuf.Reset()
bodyBuf.B, err = ext.ReadBodyWithStreaming(zr, contentLength, maxBodySize, bodyBuf.B)
if err != nil {
hlog.Infof("ext.ReadBodyWithStreaming err = %v", err)
if errors.Is(err, errs.ErrBodyTooLarge) {
req.Header.SetContentLength(contentLength)
req.ConstructBodyStream(bodyBuf, ext.AcquireBodyStream(bodyBuf, zr, req.Header.Trailer(), contentLength))
Expand Down
2 changes: 2 additions & 0 deletions pkg/protocol/http1/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"crypto/tls"
"errors"
"github.com/cloudwego/hertz/pkg/common/hlog"
"io"
"net"
"sync"
Expand Down Expand Up @@ -233,6 +234,7 @@ func (s Server) Serve(c context.Context, conn network.Conn) (err error) {
}
// Read body
if s.StreamRequestBody {
hlog.Infof("Read stream req body MaxRequestBodySize = %d", s.MaxRequestBodySize)
err = req.ReadBodyStream(&ctx.Request, zr, s.MaxRequestBodySize, s.GetOnly, !s.DisablePreParseMultipartForm)
} else {
err = req.ReadLimitBody(&ctx.Request, zr, s.MaxRequestBodySize, s.GetOnly, !s.DisablePreParseMultipartForm)
Expand Down

0 comments on commit 6f9797a

Please sign in to comment.