Skip to content

Commit 5dfc9df

Browse files
authored
Merge pull request #117 from fastly/cw/buflen
Use known and adaptive buffer sizes to lower generated garbage
2 parents bcb1f0a + 907cc49 commit 5dfc9df

File tree

8 files changed

+240
-212
lines changed

8 files changed

+240
-212
lines changed

.github/actions/install-tinygo/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ runs:
1010
steps:
1111
- run: |
1212
echo "Install TinyGo ${{ inputs.tinygo-version }}..."
13-
wget https://github.com/tinygo-org/tinygo/releases/download/v${{ inputs.tinygo-version }}/tinygo_${{ inputs.tinygo-version }}_amd64.deb
13+
wget --no-verbose https://github.com/tinygo-org/tinygo/releases/download/v${{ inputs.tinygo-version }}/tinygo_${{ inputs.tinygo-version }}_amd64.deb
1414
sudo dpkg -i tinygo_${{ inputs.tinygo-version }}_amd64.deb
1515
echo "/usr/local/tinygo/bin" >> $GITHUB_PATH
1616
shell: "bash"

fsthttp/limits.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,23 @@ func (limits *Limits) SetMaxHeaderValueLen(len int) {
2929
}
3030

3131
// MaxMethodLen gets the request method limit
32+
// Deprecated: the limit is not enforced, buffer sizing is adaptive.
3233
func (limits *Limits) MaxMethodLen() int {
3334
return limits.maxMethodLen
3435
}
3536

3637
// SetMaxMethodLen sets the request method limit
37-
func (limits *Limits) SetMaxMethodLen(len int) {
38-
limits.maxMethodLen = len
38+
// Deprecated: the limit is not reset, buffer sizing is adaptive.
39+
func (limits *Limits) SetMaxMethodLen(_ int) {
3940
}
4041

4142
// MaxURLLen gets the request URL limit
43+
// Deprecated: the limit is not enforced, buffer sizing is adaptive.
4244
func (limits *Limits) MaxURLLen() int {
4345
return limits.maxURLLen
4446
}
4547

4648
// SetMaxURLLen sets the request URL limit
47-
func (limits *Limits) SetMaxURLLen(len int) {
48-
limits.maxURLLen = len
49+
// Deprecated: the limit is not reset, buffer sizing is adaptive.
50+
func (limits *Limits) SetMaxURLLen(_ int) {
4951
}

fsthttp/request.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ import (
1717

1818
// RequestLimits are the limits for the components of an HTTP request.
1919
var RequestLimits = Limits{
20-
maxHeaderNameLen: fastly.DefaultMaxHeaderNameLen,
21-
maxHeaderValueLen: fastly.DefaultMaxHeaderValueLen,
22-
maxMethodLen: fastly.DefaultMaxMethodLen,
23-
maxURLLen: fastly.DefaultMaxURLLen,
20+
maxHeaderNameLen: fastly.DefaultLargeBufLen,
21+
maxHeaderValueLen: fastly.DefaultLargeBufLen,
22+
maxMethodLen: fastly.DefaultMediumBufLen,
23+
maxURLLen: fastly.DefaultLargeBufLen,
2424
}
2525

2626
// Request represents an HTTP request received by this server from a requesting
@@ -133,12 +133,12 @@ func newClientRequest() (*Request, error) {
133133
return nil, fmt.Errorf("get client request and body: %w", err)
134134
}
135135

136-
method, err := abiReq.GetMethod(RequestLimits.maxMethodLen)
136+
method, err := abiReq.GetMethod()
137137
if err != nil {
138138
return nil, fmt.Errorf("get method: %w", err)
139139
}
140140

141-
uri, err := abiReq.GetURI(RequestLimits.maxURLLen)
141+
uri, err := abiReq.GetURI()
142142
if err != nil {
143143
return nil, fmt.Errorf("get URI: %w", err)
144144
}

fsthttp/response.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212

1313
// ResponseLimits are the limits for the components of an HTTP response.
1414
var ResponseLimits = Limits{
15-
maxHeaderNameLen: fastly.DefaultMaxHeaderNameLen,
16-
maxHeaderValueLen: fastly.DefaultMaxHeaderValueLen,
15+
maxHeaderNameLen: fastly.DefaultLargeBufLen,
16+
maxHeaderValueLen: fastly.DefaultLargeBufLen,
1717
}
1818

1919
// Response to an outgoing HTTP request made by this server.

0 commit comments

Comments
 (0)