MCPcopy Create free account
hub / github.com/imroc/req / frameScratchBufferLen

Method frameScratchBufferLen

internal/http2/transport.go:1649–1666  ·  view source on GitHub ↗

frameScratchBufferLen returns the length of a buffer to use for outgoing request bodies to read/write to/from. It returns max(1, min(peer's advertised max frame size, Request.ContentLength+1, 512KB)).

(maxFrameSize int)

Source from the content-addressed store, hash-verified

1647// It returns max(1, min(peer's advertised max frame size,
1648// Request.ContentLength+1, 512KB)).
1649func (cs *clientStream) frameScratchBufferLen(maxFrameSize int) int {
1650 const max = 512 << 10
1651 n := int64(maxFrameSize)
1652 if n > max {
1653 n = max
1654 }
1655 if cl := cs.reqBodyContentLength; cl != -1 && cl+1 < n {
1656 // Add an extra byte past the declared content-length to
1657 // give the caller's Request.Body io.textprotoReader a chance to
1658 // give us more bytes than they declared, so we can catch it
1659 // early.
1660 n = cl + 1
1661 }
1662 if n < 1 {
1663 return 1
1664 }
1665 return int(n) // doesn't truncate; max is 512K
1666}
1667
1668// Seven bufPools manage different frame sizes. This helps to avoid scenarios where long-running
1669// streaming requests using small frame sizes occupy large buffers initially allocated for prior

Callers 1

writeRequestBodyMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected