dedue
parent
6c67686b99
commit
6b18d2031a
27
server.go
27
server.go
|
|
@ -55,6 +55,7 @@ func (s *Server) Connect(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|
||||||
hijacker, ok := w.(http.Hijacker)
|
hijacker, ok := w.(http.Hijacker)
|
||||||
if !ok {
|
if !ok {
|
||||||
s.Error(w, errors.New("hijack not available"))
|
s.Error(w, errors.New("hijack not available"))
|
||||||
|
|
@ -67,21 +68,8 @@ func (s *Server) Connect(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
xfer := func(dst io.WriteCloser, src io.ReadCloser) {
|
go s.xfer(r.Context(), dest, client)
|
||||||
defer dst.Close()
|
go s.xfer(r.Context(), client, dest)
|
||||||
defer src.Close()
|
|
||||||
io.Copy(
|
|
||||||
throttledWriter{
|
|
||||||
ctx: context.Background(),
|
|
||||||
w: dst,
|
|
||||||
limiter: s.limiter,
|
|
||||||
},
|
|
||||||
src,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
go xfer(dest, client)
|
|
||||||
go xfer(client, dest)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) Serve(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) Serve(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
@ -98,12 +86,17 @@ func (s *Server) Serve(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Add(k, s)
|
w.Header().Add(k, s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
s.xfer(r.Context(), w, resp.Body)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Server) xfer(ctx context.Context, w io.Writer, r io.ReadCloser) {
|
||||||
|
defer r.Close()
|
||||||
io.Copy(
|
io.Copy(
|
||||||
throttledWriter{
|
throttledWriter{
|
||||||
ctx: r.Context(),
|
ctx: ctx,
|
||||||
w: w,
|
w: w,
|
||||||
limiter: s.limiter,
|
limiter: s.limiter,
|
||||||
},
|
},
|
||||||
resp.Body,
|
r,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue