mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-22 21:49:22 +00:00
This commit is contained in:
parent
37d8d3afe9
commit
ce8d4cc80b
|
@ -13,7 +13,7 @@ github.com/codegangsta/cli = commit:7381bc4e62
|
||||||
github.com/go-sql-driver/mysql = commit:8111ee3ec3
|
github.com/go-sql-driver/mysql = commit:8111ee3ec3
|
||||||
github.com/go-xorm/core = commit:3e0fa232ab
|
github.com/go-xorm/core = commit:3e0fa232ab
|
||||||
github.com/go-xorm/xorm = commit:58d33844ce
|
github.com/go-xorm/xorm = commit:58d33844ce
|
||||||
github.com/gogits/go-gogs-client = commit:a5c3262f5e
|
github.com/gogits/go-gogs-client = commit:3b1d86c3a8
|
||||||
github.com/gogits/oauth2 = commit:99cbec870a
|
github.com/gogits/oauth2 = commit:99cbec870a
|
||||||
github.com/lib/pq = commit:b021d0ef20
|
github.com/lib/pq = commit:b021d0ef20
|
||||||
github.com/macaron-contrib/binding = commit:0e23661e7d
|
github.com/macaron-contrib/binding = commit:0e23661e7d
|
||||||
|
|
|
@ -108,6 +108,7 @@ var (
|
||||||
|
|
||||||
// CheckPublicKeyString checks if the given public key string is recognized by SSH.
|
// CheckPublicKeyString checks if the given public key string is recognized by SSH.
|
||||||
func CheckPublicKeyString(content string) (bool, error) {
|
func CheckPublicKeyString(content string) (bool, error) {
|
||||||
|
content = strings.TrimRight(content, "\n\r")
|
||||||
if strings.ContainsAny(content, "\n\r") {
|
if strings.ContainsAny(content, "\n\r") {
|
||||||
return false, errors.New("only a single line with a single key please")
|
return false, errors.New("only a single line with a single key please")
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
package httplib
|
package httplib
|
||||||
|
|
||||||
// NOTE: last sync c07b1d8 on Aug 23, 2014.
|
// NOTE: last sync 57e62e5 on Oct 29, 2014.
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
@ -14,6 +14,7 @@ import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -252,35 +253,36 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) {
|
||||||
} else {
|
} else {
|
||||||
b.url = b.url + "?" + paramBody
|
b.url = b.url + "?" + paramBody
|
||||||
}
|
}
|
||||||
} else if b.req.Method == "POST" && b.req.Body == nil && len(paramBody) > 0 {
|
} else if b.req.Method == "POST" && b.req.Body == nil {
|
||||||
if len(b.files) > 0 {
|
if len(b.files) > 0 {
|
||||||
bodyBuf := &bytes.Buffer{}
|
pr, pw := io.Pipe()
|
||||||
bodyWriter := multipart.NewWriter(bodyBuf)
|
bodyWriter := multipart.NewWriter(pw)
|
||||||
for formname, filename := range b.files {
|
go func() {
|
||||||
fileWriter, err := bodyWriter.CreateFormFile(formname, filename)
|
for formname, filename := range b.files {
|
||||||
if err != nil {
|
fileWriter, err := bodyWriter.CreateFormFile(formname, filename)
|
||||||
return nil, err
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
fh, err := os.Open(filename)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
//iocopy
|
||||||
|
_, err = io.Copy(fileWriter, fh)
|
||||||
|
fh.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fh, err := os.Open(filename)
|
for k, v := range b.params {
|
||||||
if err != nil {
|
bodyWriter.WriteField(k, v)
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
//iocopy
|
bodyWriter.Close()
|
||||||
_, err = io.Copy(fileWriter, fh)
|
pw.Close()
|
||||||
fh.Close()
|
}()
|
||||||
if err != nil {
|
b.Header("Content-Type", bodyWriter.FormDataContentType())
|
||||||
return nil, err
|
b.req.Body = ioutil.NopCloser(pr)
|
||||||
}
|
} else if len(paramBody) > 0 {
|
||||||
}
|
|
||||||
for k, v := range b.params {
|
|
||||||
bodyWriter.WriteField(k, v)
|
|
||||||
}
|
|
||||||
contentType := bodyWriter.FormDataContentType()
|
|
||||||
bodyWriter.Close()
|
|
||||||
b.Header("Content-Type", contentType)
|
|
||||||
b.req.Body = ioutil.NopCloser(bodyBuf)
|
|
||||||
b.req.ContentLength = int64(bodyBuf.Len())
|
|
||||||
} else {
|
|
||||||
b.Header("Content-Type", "application/x-www-form-urlencoded")
|
b.Header("Content-Type", "application/x-www-form-urlencoded")
|
||||||
b.Body(paramBody)
|
b.Body(paramBody)
|
||||||
}
|
}
|
||||||
|
@ -332,7 +334,7 @@ func (b *BeegoHttpRequest) getResponse() (*http.Response, error) {
|
||||||
Jar: jar,
|
Jar: jar,
|
||||||
}
|
}
|
||||||
|
|
||||||
if b.setting.UserAgent != "" {
|
if len(b.setting.UserAgent) > 0 && len(b.req.Header.Get("User-Agent")) == 0 {
|
||||||
b.req.Header.Set("User-Agent", b.setting.UserAgent)
|
b.req.Header.Set("User-Agent", b.setting.UserAgent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,23 +57,23 @@ func TestSimplePost(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPostFile(t *testing.T) {
|
// func TestPostFile(t *testing.T) {
|
||||||
v := "smallfish"
|
// v := "smallfish"
|
||||||
req := Post("http://httpbin.org/post")
|
// req := Post("http://httpbin.org/post")
|
||||||
req.Param("username", v)
|
// req.Param("username", v)
|
||||||
req.PostFile("uploadfile", "httplib_test.go")
|
// req.PostFile("uploadfile", "httplib_test.go")
|
||||||
|
|
||||||
str, err := req.String()
|
// str, err := req.String()
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
t.Fatal(err)
|
// t.Fatal(err)
|
||||||
}
|
// }
|
||||||
t.Log(str)
|
// t.Log(str)
|
||||||
|
|
||||||
n := strings.Index(str, v)
|
// n := strings.Index(str, v)
|
||||||
if n == -1 {
|
// if n == -1 {
|
||||||
t.Fatal(v + " not found in post")
|
// t.Fatal(v + " not found in post")
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
func TestSimplePut(t *testing.T) {
|
func TestSimplePut(t *testing.T) {
|
||||||
str, err := Put("http://httpbin.org/put").String()
|
str, err := Put("http://httpbin.org/put").String()
|
||||||
|
@ -194,3 +194,13 @@ func TestToFile(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHeader(t *testing.T) {
|
||||||
|
req := Get("http://httpbin.org/headers")
|
||||||
|
req.Header("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36")
|
||||||
|
str, err := req.String()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
t.Log(str)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue