https.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. routeConfig.Domain = domain
  31. l, errRet := pxy.rc.VhostHttpsMuxer.Listen(routeConfig)
  32. if errRet != nil {
  33. err = errRet
  34. return
  35. }
  36. l.AddLogPrefix(pxy.name)
  37. pxy.Info("https proxy listen for host [%s]", routeConfig.Domain)
  38. pxy.listeners = append(pxy.listeners, l)
  39. addrs = append(addrs, util.CanonicalAddr(routeConfig.Domain, g.GlbServerCfg.VhostHttpsPort))
  40. }
  41. if pxy.cfg.SubDomain != "" {
  42. routeConfig.Domain = pxy.cfg.SubDomain + "." + g.GlbServerCfg.SubDomainHost
  43. l, errRet := pxy.rc.VhostHttpsMuxer.Listen(routeConfig)
  44. if errRet != nil {
  45. err = errRet
  46. return
  47. }
  48. l.AddLogPrefix(pxy.name)
  49. pxy.Info("https proxy listen for host [%s]", routeConfig.Domain)
  50. pxy.listeners = append(pxy.listeners, l)
  51. addrs = append(addrs, util.CanonicalAddr(routeConfig.Domain, int(g.GlbServerCfg.VhostHttpsPort)))
  52. }
  53. pxy.startListenHandler(pxy, HandleUserTcpConnection)
  54. remoteAddr = strings.Join(addrs, ",")
  55. return
  56. }
  57. func (pxy *HttpsProxy) GetConf() config.ProxyConf {
  58. return pxy.cfg
  59. }
  60. func (pxy *HttpsProxy) Close() {
  61. pxy.BaseProxy.Close()
  62. }