@@ -189,13 +189,16 @@ func (pxy *TcpProxy) Close() {
189189type HttpProxy struct {
190190 BaseProxy
191191 cfg * config.HttpProxyConf
192+
193+ closeFuncs []func ()
192194}
193195
194196func (pxy * HttpProxy ) Run () (err error ) {
195- routeConfig := & vhost.VhostRouteConfig {
196- RewriteHost : pxy .cfg .HostHeaderRewrite ,
197- Username : pxy .cfg .HttpUser ,
198- Password : pxy .cfg .HttpPwd ,
197+ routeConfig := vhost.VhostRouteConfig {
198+ RewriteHost : pxy .cfg .HostHeaderRewrite ,
199+ Username : pxy .cfg .HttpUser ,
200+ Password : pxy .cfg .HttpPwd ,
201+ CreateConnFn : pxy .GetRealConn ,
199202 }
200203
201204 locations := pxy .cfg .Locations
@@ -206,40 +209,69 @@ func (pxy *HttpProxy) Run() (err error) {
206209 routeConfig .Domain = domain
207210 for _ , location := range locations {
208211 routeConfig .Location = location
209- l , err := pxy .ctl .svr .VhostHttpMuxer . Listen (routeConfig )
212+ err := pxy .ctl .svr .httpReverseProxy . Register (routeConfig )
210213 if err != nil {
211214 return err
212215 }
213- l .AddLogPrefix (pxy .name )
216+ tmpDomain := routeConfig .Domain
217+ tmpLocation := routeConfig .Location
218+ pxy .closeFuncs = append (pxy .closeFuncs , func () {
219+ pxy .ctl .svr .httpReverseProxy .UnRegister (tmpDomain , tmpLocation )
220+ })
214221 pxy .Info ("http proxy listen for host [%s] location [%s]" , routeConfig .Domain , routeConfig .Location )
215- pxy .listeners = append (pxy .listeners , l )
216222 }
217223 }
218224
219225 if pxy .cfg .SubDomain != "" {
220226 routeConfig .Domain = pxy .cfg .SubDomain + "." + config .ServerCommonCfg .SubDomainHost
221227 for _ , location := range locations {
222228 routeConfig .Location = location
223- l , err := pxy .ctl .svr .VhostHttpMuxer . Listen (routeConfig )
229+ err := pxy .ctl .svr .httpReverseProxy . Register (routeConfig )
224230 if err != nil {
225231 return err
226232 }
227- l .AddLogPrefix (pxy .name )
233+ tmpDomain := routeConfig .Domain
234+ tmpLocation := routeConfig .Location
235+ pxy .closeFuncs = append (pxy .closeFuncs , func () {
236+ pxy .ctl .svr .httpReverseProxy .UnRegister (tmpDomain , tmpLocation )
237+ })
228238 pxy .Info ("http proxy listen for host [%s] location [%s]" , routeConfig .Domain , routeConfig .Location )
229- pxy .listeners = append (pxy .listeners , l )
230239 }
231240 }
232-
233- pxy .startListenHandler (pxy , HandleUserTcpConnection )
234241 return
235242}
236243
237244func (pxy * HttpProxy ) GetConf () config.ProxyConf {
238245 return pxy .cfg
239246}
240247
248+ func (pxy * HttpProxy ) GetRealConn () (workConn frpNet.Conn , err error ) {
249+ tmpConn , errRet := pxy .GetWorkConnFromPool ()
250+ if errRet != nil {
251+ err = errRet
252+ return
253+ }
254+
255+ var rwc io.ReadWriteCloser = tmpConn
256+ if pxy .cfg .UseEncryption {
257+ rwc , err = frpIo .WithEncryption (rwc , []byte (config .ServerCommonCfg .PrivilegeToken ))
258+ if err != nil {
259+ pxy .Error ("create encryption stream error: %v" , err )
260+ return
261+ }
262+ }
263+ if pxy .cfg .UseCompression {
264+ rwc = frpIo .WithCompression (rwc )
265+ }
266+ workConn = frpNet .WrapReadWriteCloserToConn (rwc , tmpConn )
267+ return
268+ }
269+
241270func (pxy * HttpProxy ) Close () {
242271 pxy .BaseProxy .Close ()
272+ for _ , closeFn := range pxy .closeFuncs {
273+ closeFn ()
274+ }
243275}
244276
245277type HttpsProxy struct {
0 commit comments