git.iko.soy/typeable/oauth2-proxy
on master help sign in
Use pagewriter to render robots txt page
f3bd61bJoel Speed
oauthproxy.go+1−7
@@ -577,13 +577,7 @@ func (p *OAuthProxy) serveHTTP(rw http.ResponseWriter, req *http.Request) {
577
577
578// RobotsTxt disallows scraping pages from the OAuthProxy
578// RobotsTxt disallows scraping pages from the OAuthProxy
579func (p *OAuthProxy) RobotsTxt(rw http.ResponseWriter, req *http.Request) {
579func (p *OAuthProxy) RobotsTxt(rw http.ResponseWriter, req *http.Request) {
580− _, err := fmt.Fprintf(rw, "User-agent: *\nDisallow: /")
580+ p.pageWriter.WriteRobotsTxt(rw, req)
581− if err != nil {
582− logger.Printf("Error writing robots.txt: %v", err)
583− p.ErrorPage(rw, req, http.StatusInternalServerError, err.Error())
584− return
585− }
586− rw.WriteHeader(http.StatusOK)
587}
581}
588
582
589// ErrorPage writes an error response
583// ErrorPage writes an error response
oauthproxy_test.go+1−1
@@ -57,7 +57,7 @@ func TestRobotsTxt(t *testing.T) {
57 req, _ := http.NewRequest("GET", "/robots.txt", nil)
57 req, _ := http.NewRequest("GET", "/robots.txt", nil)
58 proxy.ServeHTTP(rw, req)
58 proxy.ServeHTTP(rw, req)
59 assert.Equal(t, 200, rw.Code)
59 assert.Equal(t, 200, rw.Code)
60− assert.Equal(t, "User-agent: *\nDisallow: /", rw.Body.String())
60+ assert.Equal(t, "User-agent: *\nDisallow: /\n", rw.Body.String())
61}
61}
62
62
63func TestIsValidRedirect(t *testing.T) {
63func TestIsValidRedirect(t *testing.T) {