Skip to content

Commit

Permalink
Add toggle to allow empty Content-Length headers
Browse files Browse the repository at this point in the history
In go 1.22, they are changing the default behavior in the `net/http`
standard library to **REJECT** requests and responses containing an
invalid, empty `Content-Length` header.
Source: https://tip.golang.org/doc/go1.22#minor_library_changes

As per the authors,
> The previous behavior may be restored by setting GODEBUG field httplaxcontentlength=1.

This commit enables operators to set this GODEBUG field by configuring
`gorouter`'s `go.httplaxcontentlength` property.

By default, this property will be disabled and gorouter will begin to
reject requests that contain invlaid, empty `Content-Length` headers.

[#187125229](https://www.pivotaltracker.com/story/show/187125229)
  • Loading branch information
jrussett authored and geofffranks committed Mar 6, 2024
1 parent ae27eed commit 7f87626
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
8 changes: 8 additions & 0 deletions jobs/gorouter/spec
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,14 @@ properties:
street_address: []
postal_code: []
default: []

healthchecker.failure_counter_file:
description: "File used by the healthchecker to monitor consecutive failures."
default: /var/vcap/data/gorouter/counters/consecutive_healthchecker_failures.count

go.httplaxcontentlength:
description: |
Environment Flag to temporarily allow requests containing an invalid, empty `Content-Length` header for backwards compatibility.
This toggle allows operators to add the `GODEBUG` field `httplaxcontentlength=1`, as allowable per the [go 1.22 release documentation](https://tip.golang.org/doc/go1.22#minor_library_changes).
Defaults to `false` as the default behavior in go 1.22+ is to reject these requests.
default: false
4 changes: 4 additions & 0 deletions jobs/gorouter/templates/bpm.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@ bpm = {
]
}

if p('go.httplaxcontentlength') == true
bpm['processes'][0]['env']['GODEBUG'] << ',httplaxcontentlength=1'
end

YAML.dump(bpm)
%>
25 changes: 25 additions & 0 deletions spec/gorouter_templates_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1628,6 +1628,31 @@
end
end
end

describe 'bpm' do
let(:deployment_manifest_fragment) { {} }
let(:template) { job.template('config/bpm.yml') }
let(:rendered_template) { template.render(deployment_manifest_fragment) }
subject(:parsed_yaml) { YAML.safe_load(rendered_template) }

context 'GODEBUG' do
it 'defaults to netdns=cgo' do
expect(parsed_yaml['processes'][0]['env']['GODEBUG']).to eq('netdns=cgo')
end

context 'when go.HTTPLaxContentLength is enabled' do
before do
deployment_manifest_fragment['go'] = {
'httplaxcontentlength' => true,
}
end

it 'sets httplaxcontentlength=1 correctly' do
expect(parsed_yaml['processes'][0]['env']['GODEBUG']).to eq('netdns=cgo,httplaxcontentlength=1')
end
end
end
end
end

# rubocop:enable Layout/LineLength
Expand Down

0 comments on commit 7f87626

Please sign in to comment.