1
0

https.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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/models/config"
  18. "github.com/fatedier/frp/utils/util"
  19. "github.com/fatedier/frp/utils/vhost"
  20. )
  21. type HttpsProxy struct {
  22. *BaseProxy
  23. cfg *config.HttpsProxyConf
  24. }
  25. func (pxy *HttpsProxy) Run() (remoteAddr string, err error) {
  26. routeConfig := &vhost.VhostRouteConfig{}
  27. defer func() {
  28. if err != nil {
  29. pxy.Close()
  30. }
  31. }()
  32. addrs := make([]string, 0)
  33. for _, domain := range pxy.cfg.CustomDomains {
  34. if domain == "" {
  35. continue
  36. }
  37. routeConfig.Domain = domain
  38. l, errRet := pxy.rc.VhostHttpsMuxer.Listen(routeConfig)
  39. if errRet != nil {
  40. err = errRet
  41. return
  42. }
  43. l.AddLogPrefix(pxy.name)
  44. pxy.Info("https proxy listen for host [%s]", routeConfig.Domain)
  45. pxy.listeners = append(pxy.listeners, l)
  46. addrs = append(addrs, util.CanonicalAddr(routeConfig.Domain, pxy.serverCfg.VhostHttpsPort))
  47. }
  48. if pxy.cfg.SubDomain != "" {
  49. routeConfig.Domain = pxy.cfg.SubDomain + "." + pxy.serverCfg.SubDomainHost
  50. l, errRet := pxy.rc.VhostHttpsMuxer.Listen(routeConfig)
  51. if errRet != nil {
  52. err = errRet
  53. return
  54. }
  55. l.AddLogPrefix(pxy.name)
  56. pxy.Info("https proxy listen for host [%s]", routeConfig.Domain)
  57. pxy.listeners = append(pxy.listeners, l)
  58. addrs = append(addrs, util.CanonicalAddr(routeConfig.Domain, int(pxy.serverCfg.VhostHttpsPort)))
  59. }
  60. pxy.startListenHandler(pxy, HandleUserTcpConnection)
  61. remoteAddr = strings.Join(addrs, ",")
  62. return
  63. }
  64. func (pxy *HttpsProxy) GetConf() config.ProxyConf {
  65. return pxy.cfg
  66. }
  67. func (pxy *HttpsProxy) Close() {
  68. pxy.BaseProxy.Close()
  69. }