A fork of Gitea (see branch `mj`) adding Majority Judgment Polls 𐄷 over Issues and Merge Requests. https://git.mieuxvoter.fr
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.2 KiB

  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. "fmt"
  8. "net"
  9. "net/http"
  10. "code.gitea.io/gitea/modules/httplib"
  11. "code.gitea.io/gitea/modules/setting"
  12. jsoniter "github.com/json-iterator/go"
  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. json := jsoniter.ConfigCompatibleWithStandardLibrary
  25. err := json.NewDecoder(resp.Body).Decode(&res)
  26. if err != nil {
  27. res.Err = err.Error()
  28. }
  29. return &res
  30. }
  31. func newInternalRequest(url, method string) *httplib.Request {
  32. req := newRequest(url, method).SetTLSClientConfig(&tls.Config{
  33. InsecureSkipVerify: true,
  34. ServerName: setting.Domain,
  35. })
  36. if setting.Protocol == setting.UnixSocket {
  37. req.SetTransport(&http.Transport{
  38. Dial: func(_, _ string) (net.Conn, error) {
  39. return net.Dial("unix", setting.HTTPAddr)
  40. },
  41. })
  42. }
  43. return req
  44. }