Skip to content

Commit

Permalink
redirect to home page
Browse files Browse the repository at this point in the history
  • Loading branch information
faceair committed Jun 19, 2018
1 parent a7ca879 commit 13aef5e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
}
}
Expand Down

0 comments on commit 13aef5e

Please sign in to comment.