https.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2019 fatedier, fatedier@gmail.com
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package proxy
  15. import (
  16. "strings"
  17. "github.com/fatedier/frp/g"
  18. "github.com/fatedier/frp/models/config"
  19. "github.com/fatedier/frp/utils/util"
  20. "github.com/fatedier/frp/utils/vhost"
  21. )
  22. type HttpsProxy struct {
  23. *BaseProxy
  24. cfg *config.HttpsProxyConf
  25. }
  26. func (pxy *HttpsProxy) Run() (remoteAddr string, err error) {
  27. routeConfig := &vhost.VhostRouteConfig{}
  28. addrs := make([]string, 0)
  29. for _, domain := range pxy.cfg.CustomDomains {
  30. if domain == "" {
  31. continue
  32. }
  33. routeConfig.Domain = domain
  34. l, errRet := pxy.rc.VhostHttpsMuxer.Listen(routeConfig)
  35. if errRet != nil {
  36. err = errRet
  37. return
  38. }
  39. l.AddLogPrefix(pxy.name)
  40. pxy.Info("https proxy listen for host [%s]", routeConfig.Domain)
  41. pxy.listeners = append(pxy.listeners, l)
  42. addrs = append(addrs, util.CanonicalAddr(routeConfig.Domain, g.GlbServerCfg.VhostHttpsPort))
  43. }
  44. if pxy.cfg.SubDomain != "" {
  45. routeConfig.Domain = pxy.cfg.SubDomain + "." + g.GlbServerCfg.SubDomainHost
  46. l, errRet := pxy.rc.VhostHttpsMuxer.Listen(routeConfig)
  47. if errRet != nil {
  48. err = errRet
  49. return
  50. }
  51. l.AddLogPrefix(pxy.name)
  52. pxy.Info("https proxy listen for host [%s]", routeConfig.Domain)
  53. pxy.listeners = append(pxy.listeners, l)
  54. addrs = append(addrs, util.CanonicalAddr(routeConfig.Domain, int(g.GlbServerCfg.VhostHttpsPort)))
  55. }
  56. pxy.startListenHandler(pxy, HandleUserTcpConnection)
  57. remoteAddr = strings.Join(addrs, ",")
  58. return
  59. }
  60. func (pxy *HttpsProxy) GetConf() config.ProxyConf {
  61. return pxy.cfg
  62. }
  63. func (pxy *HttpsProxy) Close() {
  64. pxy.BaseProxy.Close()
  65. }