Skip to content

Commit 031d2f9

Browse files
committed
Merge pull request letsencrypt#1449 from letsencrypt/ocsp_response_200
ocsp-responder: 200 on GET /
2 parents ee26b8b + c156f99 commit 031d2f9

File tree

2 files changed

+43
-21
lines changed

2 files changed

+43
-21
lines changed

cmd/ocsp-responder/main.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,10 @@ func main() {
177177
cmd.FailOnError(err, "Couldn't parse shutdown stop timeout")
178178
killTimeout, err := time.ParseDuration(c.OCSPResponder.ShutdownKillTimeout)
179179
cmd.FailOnError(err, "Couldn't parse shutdown kill timeout")
180-
181-
m := http.StripPrefix(c.OCSPResponder.Path, cfocsp.NewResponder(source))
182-
183-
httpMonitor := metrics.NewHTTPMonitor(stats, m, "OCSP")
180+
m := mux(stats, c.OCSPResponder.Path, source)
184181
srv := &http.Server{
185182
Addr: c.OCSPResponder.ListenAddress,
186-
Handler: httpMonitor.Handle(),
183+
Handler: m,
187184
}
188185

189186
hd := &httpdown.HTTP{
@@ -197,3 +194,18 @@ func main() {
197194

198195
app.Run()
199196
}
197+
198+
func mux(stats statsd.Statter, responderPath string, source cfocsp.Source) http.Handler {
199+
m := http.StripPrefix(responderPath, cfocsp.NewResponder(source))
200+
h := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
201+
if r.Method == "GET" && r.URL.Path == "/" {
202+
w.Header().Set("Cache-Control", "max-age=43200") // Cache for 12 hours
203+
w.WriteHeader(200)
204+
return
205+
}
206+
m.ServeHTTP(w, r)
207+
})
208+
mon := metrics.NewHTTPMonitor(stats, h, "OCSP")
209+
return mon.Handle()
210+
211+
}

cmd/ocsp-responder/main_test.go

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import (
1010
"testing"
1111
"time"
1212

13+
"github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/cactus/go-statsd-client/statsd"
1314
cfocsp "github.com/letsencrypt/boulder/Godeps/_workspace/src/github.com/cloudflare/cfssl/ocsp"
1415
"github.com/letsencrypt/boulder/Godeps/_workspace/src/golang.org/x/crypto/ocsp"
15-
1616
"github.com/letsencrypt/boulder/core"
1717
blog "github.com/letsencrypt/boulder/log"
1818
"github.com/letsencrypt/boulder/mocks"
@@ -22,30 +22,40 @@ import (
2222
)
2323

2424
var (
25-
req = mustRead("./testdata/ocsp.req")
26-
resp = mustRead("./testdata/ocsp.resp")
25+
req = mustRead("./testdata/ocsp.req")
26+
resp = mustRead("./testdata/ocsp.resp")
27+
stats, _ = statsd.NewNoopClient()
2728
)
2829

29-
func TestHandler(t *testing.T) {
30+
func TestMux(t *testing.T) {
3031
ocspReq, err := ocsp.ParseRequest(req)
3132
if err != nil {
3233
t.Fatalf("ocsp.ParseRequest: %s", err)
3334
}
3435
src := make(cfocsp.InMemorySource)
3536
src[ocspReq.SerialNumber.String()] = resp
36-
37-
h := cfocsp.NewResponder(src)
38-
w := httptest.NewRecorder()
39-
r, err := http.NewRequest("POST", "/", bytes.NewReader(req))
40-
if err != nil {
41-
t.Fatal(err)
37+
h := mux(stats, "/foobar/", src)
38+
type muxTest struct {
39+
method string
40+
path string
41+
reqBody []byte
42+
respBody []byte
4243
}
43-
h.ServeHTTP(w, r)
44-
if w.Code != http.StatusOK {
45-
t.Errorf("Code: want %d, got %d", http.StatusOK, w.Code)
46-
}
47-
if !bytes.Equal(w.Body.Bytes(), resp) {
48-
t.Errorf("Mismatched body: want %#v, got %#v", resp, w.Body.Bytes())
44+
mts := []muxTest{{"POST", "/foobar/", req, resp}, {"GET", "/", nil, nil}}
45+
for i, mt := range mts {
46+
w := httptest.NewRecorder()
47+
r, err := http.NewRequest(mt.method, mt.path, bytes.NewReader(mt.reqBody))
48+
if err != nil {
49+
t.Fatalf("#%d, NewRequest: %s", i, err)
50+
}
51+
h.ServeHTTP(w, r)
52+
if w.Code != http.StatusOK {
53+
t.Errorf("Code: want %d, got %d", http.StatusOK, w.Code)
54+
}
55+
if !bytes.Equal(w.Body.Bytes(), mt.respBody) {
56+
t.Errorf("Mismatched body: want %#v, got %#v", mt.respBody, w.Body.Bytes())
57+
}
58+
4959
}
5060
}
5161

0 commit comments

Comments
 (0)