Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/bosh-dns/dns/server/handlers/cache_handler.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package handlers

import (
"context"

"code.cloudfoundry.org/clock"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
"github.com/coredns/coredns/plugin/cache"
"github.com/miekg/dns"
"golang.org/x/net/context"

"bosh-dns/dns/server/handlers/internal"
"bosh-dns/dns/server/records/dnsresolver"
Expand All @@ -24,6 +25,12 @@ type requestContext struct {
fromCache bool
}

type ctxKey int

const (
indicatorKey ctxKey = iota
)

func NewCachingDNSHandler(next dns.Handler, truncater dnsresolver.ResponseTruncater, clock clock.Clock, logger boshlog.Logger) CachingDNSHandler {
ca := cache.New()
ca.Next = corednsHandlerWrapper{Next: next}
Expand Down Expand Up @@ -54,7 +61,7 @@ func (c CachingDNSHandler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
indicator := &requestContext{
fromCache: true,
}
requestContext := context.WithValue(context.Background(), "indicator", indicator)
requestContext := context.WithValue(context.Background(), indicatorKey, indicator)

before := c.clock.Now()
_, err := c.ca.ServeDNS(requestContext, truncatingWriter, r)
Expand All @@ -73,7 +80,7 @@ type corednsHandlerWrapper struct {
}

func (w corednsHandlerWrapper) ServeDNS(ctx context.Context, writer dns.ResponseWriter, m *dns.Msg) (int, error) {
requestContext := ctx.Value("indicator").(*requestContext)
requestContext := ctx.Value(indicatorKey).(*requestContext)
requestContext.fromCache = false

w.Next.ServeDNS(writer, m)
Expand Down
Loading