From 13aef5e9908ceca24af3a04d881969add67379c0 Mon Sep 17 00:00:00 2001 From: faceair Date: Tue, 19 Jun 2018 11:46:03 +0800 Subject: [PATCH] redirect to home page --- git/git.go | 11 ++++++++++- git/git_test.go | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/git/git.go b/git/git.go index 8263c5f..33b1add 100644 --- a/git/git.go +++ b/git/git.go @@ -44,7 +44,7 @@ type Server struct { func (g *Server) Do(req *http.Request) (*http.Response, error) { match := vscRegex.FindStringSubmatch(req.URL.String()) if match == nil { - return betproxy.HTTPError(http.StatusBadRequest, "url not match", req), nil + return HTTPRedirect("https://github.com/faceair/gotit", req), nil } repoPath := match[1] @@ -222,3 +222,12 @@ type cloneTask struct { func (t *cloneTask) Done() chan struct{} { return t.done } + +// HTTPRedirect create a temporary redirect http.Response with giving url +func HTTPRedirect(url string, req *http.Request) *http.Response { + res := betproxy.NewResponse(http.StatusTemporaryRedirect, http.Header{ + "Location": []string{url}, + }, nil, req) + res.ContentLength = 0 + return res +} diff --git a/git/git_test.go b/git/git_test.go index 32db93e..7979101 100644 --- a/git/git_test.go +++ b/git/git_test.go @@ -34,7 +34,7 @@ func TestURLNotMatch(t *testing.T) { if err != nil { t.Error("request failed") } - if res.StatusCode != http.StatusBadRequest { + if res.StatusCode != http.StatusTemporaryRedirect { t.Error("url should not matched!") } }