本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.1KB

  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package private
  5. import (
  6. "crypto/tls"
  7. "encoding/json"
  8. "fmt"
  9. "net"
  10. "net/http"
  11. "code.gitea.io/gitea/modules/httplib"
  12. "code.gitea.io/gitea/modules/setting"
  13. )
  14. func newRequest(url, method string) *httplib.Request {
  15. return httplib.NewRequest(url, method).Header("Authorization",
  16. fmt.Sprintf("Bearer %s", setting.InternalToken))
  17. }
  18. // Response internal request response
  19. type Response struct {
  20. Err string `json:"err"`
  21. }
  22. func decodeJSONError(resp *http.Response) *Response {
  23. var res Response
  24. err := json.NewDecoder(resp.Body).Decode(&res)
  25. if err != nil {
  26. res.Err = err.Error()
  27. }
  28. return &res
  29. }
  30. func newInternalRequest(url, method string) *httplib.Request {
  31. req := newRequest(url, method).SetTLSClientConfig(&tls.Config{
  32. InsecureSkipVerify: true,
  33. ServerName: setting.Domain,
  34. })
  35. if setting.Protocol == setting.UnixSocket {
  36. req.SetTransport(&http.Transport{
  37. Dial: func(_, _ string) (net.Conn, error) {
  38. return net.Dial("unix", setting.HTTPAddr)
  39. },
  40. })
  41. }
  42. return req
  43. }
上海开阖软件有限公司 沪ICP备12045867号-1