Skip to content

Commit

Permalink
refactor: proxy api (#1656)
Browse files Browse the repository at this point in the history
* refactor: proxy api
  • Loading branch information
710leo authored Aug 2, 2023
1 parent 5b811b7 commit 15dcc60
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions center/router/router_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package router
import (
"context"
"crypto/tls"
"fmt"
"net"
"net/http"
"net/http/httputil"
Expand Down Expand Up @@ -164,10 +165,18 @@ func (rt *Router) dsProxy(c *gin.Context) {
transportPut(dsId, ds.UpdatedAt, transport)
}

modifyResponse := func(r *http.Response) error {
if r.StatusCode == http.StatusUnauthorized {
return fmt.Errorf("unauthorized access")
}
return nil
}

proxy := &httputil.ReverseProxy{
Director: director,
Transport: transport,
ErrorHandler: errFunc,
Director: director,
Transport: transport,
ErrorHandler: errFunc,
ModifyResponse: modifyResponse,
}

proxy.ServeHTTP(c.Writer, c.Request)
Expand Down

0 comments on commit 15dcc60

Please sign in to comment.