aboutsummaryrefslogtreecommitdiffstats
path: root/routers/repo/http.go
diff options
context:
space:
mode:
authorUnknwon <joe2010xtmf@163.com>2014-07-26 00:24:27 -0400
committerUnknwon <joe2010xtmf@163.com>2014-07-26 00:24:27 -0400
commit8dd07c0ddd99ae626a1ec8c06f75f27fed51269f (patch)
tree261d3c9911dabc58c1ac54e4e36b3dee24d2032b /routers/repo/http.go
parent0a739cf9ac901f54484c34bba8322418dedb09b0 (diff)
downloadgitea-8dd07c0ddd99ae626a1ec8c06f75f27fed51269f.tar.gz
gitea-8dd07c0ddd99ae626a1ec8c06f75f27fed51269f.zip
New UI merge in progress
Diffstat (limited to 'routers/repo/http.go')
-rw-r--r--routers/repo/http.go55
1 files changed, 41 insertions, 14 deletions
diff --git a/routers/repo/http.go b/routers/repo/http.go
index d22c0f8781..4ffe5ec345 100644
--- a/routers/repo/http.go
+++ b/routers/repo/http.go
@@ -6,6 +6,8 @@ package repo
import (
"bytes"
+ "encoding/base64"
+ "errors"
"fmt"
"io"
"io/ioutil"
@@ -19,16 +21,43 @@ import (
"strings"
"time"
- "github.com/go-martini/martini"
"github.com/gogits/gogs/models"
+ "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
)
-func Http(ctx *middleware.Context, params martini.Params) {
- username := params["username"]
- reponame := params["reponame"]
+func basicEncode(username, password string) string {
+ auth := username + ":" + password
+ return base64.StdEncoding.EncodeToString([]byte(auth))
+}
+
+func basicDecode(encoded string) (user string, name string, err error) {
+ var s []byte
+ s, err = base64.StdEncoding.DecodeString(encoded)
+ if err != nil {
+ return user, name, err
+ }
+
+ a := strings.Split(string(s), ":")
+ if len(a) == 2 {
+ user, name = a[0], a[1]
+ } else {
+ err = errors.New("decode failed")
+ }
+ return user, name, err
+}
+
+func authRequired(ctx *middleware.Context) {
+ ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=\".\"")
+ ctx.Data["ErrorMsg"] = "no basic auth and digit auth"
+ ctx.HTML(401, base.TplName("status/401"))
+}
+
+func Http(ctx *middleware.Context) {
+ username := ctx.Params(":username")
+ reponame := ctx.Params(":reponame")
if strings.HasSuffix(reponame, ".git") {
reponame = reponame[:len(reponame)-4]
}
@@ -50,7 +79,7 @@ func Http(ctx *middleware.Context, params martini.Params) {
if err == models.ErrUserNotExist {
ctx.Handle(404, "repo.Http(GetUserByName)", nil)
} else {
- ctx.Handle(500, "repo.Http(GetUserByName)", nil)
+ ctx.Handle(500, "repo.Http(GetUserByName)", err)
}
return
}
@@ -60,7 +89,7 @@ func Http(ctx *middleware.Context, params martini.Params) {
if err == models.ErrRepoNotExist {
ctx.Handle(404, "repo.Http(GetRepositoryByName)", nil)
} else {
- ctx.Handle(500, "repo.Http(GetRepositoryByName)", nil)
+ ctx.Handle(500, "repo.Http(GetRepositoryByName)", err)
}
return
}
@@ -75,7 +104,6 @@ func Http(ctx *middleware.Context, params martini.Params) {
if askAuth {
baHead := ctx.Req.Header.Get("Authorization")
if baHead == "" {
- // ask auth
authRequired(ctx)
return
}
@@ -142,7 +170,7 @@ func Http(ctx *middleware.Context, params martini.Params) {
if head[0] == '0' && head[1] == '0' {
size, err := strconv.ParseInt(string(input[lastLine+2:lastLine+4]), 16, 32)
if err != nil {
- log.Error("%v", err)
+ log.Error(4, "%v", err)
return
}
@@ -166,7 +194,6 @@ func Http(ctx *middleware.Context, params martini.Params) {
}
lastLine = lastLine + size
} else {
- //fmt.Println("ddddddddddd")
break
}
}
@@ -176,7 +203,7 @@ func Http(ctx *middleware.Context, params martini.Params) {
config := Config{setting.RepoRootPath, "git", true, true, f}
handler := HttpBackend(&config)
- handler(ctx.ResponseWriter, ctx.Req)
+ handler(ctx.Resp, ctx.Req)
}
type route struct {
@@ -229,7 +256,7 @@ func HttpBackend(config *Config) http.HandlerFunc {
dir, err := getGitDir(config, m[1])
if err != nil {
- log.GitLogger.Error(err.Error())
+ log.GitLogger.Error(4, err.Error())
renderNotFound(w)
return
}
@@ -283,7 +310,7 @@ func serviceRpc(rpc string, hr handler) {
err := cmd.Run()
if err != nil {
- log.GitLogger.Error(err.Error())
+ log.GitLogger.Error(4, err.Error())
return
}
@@ -366,7 +393,7 @@ func getGitDir(config *Config, fPath string) (string, error) {
cwd, err := os.Getwd()
if err != nil {
- log.GitLogger.Error(err.Error())
+ log.GitLogger.Error(4, err.Error())
return "", err
}
@@ -443,7 +470,7 @@ func gitCommand(gitBinPath, dir string, args ...string) []byte {
out, err := command.Output()
if err != nil {
- log.GitLogger.Error(err.Error())
+ log.GitLogger.Error(4, err.Error())
}
return out