Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Commit 8dc4515

Browse files
committed
Store 'http1' in routing table if HTTP/2 is disabled
- When routes are registered and HTTP/2 is disabled, persist the protocol for endpoints as 'http1', even if the message has protocol 'http2'. - It was confusing that the route registry and gorouter logs would show protocol 'http2', even if it would really use HTTP/1.1 when communicating with backends. - Enabling HTTP/2 will require restarting the gorouter, so the route registry will be regenerated with 'http2'. [cloudfoundry/routing-release#217] [cloudfoundry/routing-release#200]
1 parent 7f07844 commit 8dc4515

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

mbus/subscriber.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ type RegistryMessage struct {
4242
EndpointUpdatedAtNs int64 `json:"endpoint_updated_at_ns"`
4343
}
4444

45-
func (rm *RegistryMessage) makeEndpoint() (*route.Endpoint, error) {
45+
func (rm *RegistryMessage) makeEndpoint(http2Enabled bool) (*route.Endpoint, error) {
4646
port, useTLS, err := rm.port()
4747
if err != nil {
4848
return nil, err
@@ -53,7 +53,7 @@ func (rm *RegistryMessage) makeEndpoint() (*route.Endpoint, error) {
5353
}
5454

5555
protocol := rm.Protocol
56-
if protocol == "" {
56+
if protocol == "" || (!http2Enabled && protocol == "http2") {
5757
protocol = "http1"
5858
}
5959

@@ -95,6 +95,7 @@ type Subscriber struct {
9595
subscription *nats.Subscription
9696
reconnected <-chan Signal
9797
natsPendingLimit int
98+
http2Enabled bool
9899

99100
params startMessageParams
100101

@@ -131,6 +132,7 @@ func NewSubscriber(
131132
reconnected: reconnected,
132133
natsPendingLimit: c.NatsClientMessageBufferSize,
133134
logger: l,
135+
http2Enabled: c.EnableHTTP2,
134136
}
135137
}
136138

@@ -233,7 +235,7 @@ func (s *Subscriber) subscribeRoutes() (*nats.Subscription, error) {
233235
}
234236

235237
func (s *Subscriber) registerEndpoint(msg *RegistryMessage) {
236-
endpoint, err := msg.makeEndpoint()
238+
endpoint, err := msg.makeEndpoint(s.http2Enabled)
237239
if err != nil {
238240
s.logger.Error("Unable to register route",
239241
zap.Error(err),
@@ -248,7 +250,7 @@ func (s *Subscriber) registerEndpoint(msg *RegistryMessage) {
248250
}
249251

250252
func (s *Subscriber) unregisterEndpoint(msg *RegistryMessage) {
251-
endpoint, err := msg.makeEndpoint()
253+
endpoint, err := msg.makeEndpoint(s.http2Enabled)
252254
if err != nil {
253255
s.logger.Error("Unable to unregister route",
254256
zap.Error(err),

mbus/subscriber_test.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ var _ = Describe("Subscriber", func() {
381381
})
382382

383383
Context("when the message contains a protocol", func() {
384-
BeforeEach(func() {
384+
JustBeforeEach(func() {
385385
sub = mbus.NewSubscriber(natsClient, registry, cfg, reconnected, l)
386386
process = ifrit.Invoke(sub)
387387
Eventually(process.Ready()).Should(BeClosed())
@@ -410,6 +410,36 @@ var _ = Describe("Subscriber", func() {
410410

411411
Expect(originalEndpoint).To(Equal(expectedEndpoint))
412412
})
413+
414+
Context("when HTTP/2 is disabled and the protocol is http2", func() {
415+
BeforeEach(func() {
416+
cfg.EnableHTTP2 = false
417+
})
418+
It("constructs the endpoint with protocol 'http1'", func() {
419+
msg := mbus.RegistryMessage{
420+
Host: "host",
421+
App: "app",
422+
Protocol: "http2",
423+
Uris: []route.Uri{"test.example.com"},
424+
}
425+
426+
data, err := json.Marshal(msg)
427+
Expect(err).NotTo(HaveOccurred())
428+
429+
err = natsClient.Publish("router.register", data)
430+
Expect(err).ToNot(HaveOccurred())
431+
432+
Eventually(registry.RegisterCallCount).Should(Equal(1))
433+
_, originalEndpoint := registry.RegisterArgsForCall(0)
434+
expectedEndpoint := route.NewEndpoint(&route.EndpointOpts{
435+
Host: "host",
436+
AppId: "app",
437+
Protocol: "http1",
438+
})
439+
440+
Expect(originalEndpoint).To(Equal(expectedEndpoint))
441+
})
442+
})
413443
})
414444

415445
Context("when the message contains a tls port for route", func() {

0 commit comments

Comments
 (0)