(w http.ResponseWriter, r *http.Request)
| 145 | } |
| 146 | |
| 147 | func (m *Server) proxy(w http.ResponseWriter, r *http.Request) { |
| 148 | if m.cluster.PKIKey.EnableHTTPS { |
| 149 | var ( |
| 150 | plaintext []byte |
| 151 | err error |
| 152 | res []byte |
| 153 | jobj proto.HTTPAuthReply |
| 154 | ) |
| 155 | target := "https://" + m.leaderInfo.addr + r.URL.Path |
| 156 | if plaintext, err = m.extractClientReqInfo(r); err != nil { |
| 157 | sendErrReply(w, r, &proto.HTTPAuthReply{Code: proto.ErrCodeParamError, Msg: err.Error()}) |
| 158 | return |
| 159 | } |
| 160 | res, err = proto.SendBytes(m.authProxy.client, target, plaintext) |
| 161 | if err != nil { |
| 162 | sendErrReply(w, r, &proto.HTTPAuthReply{Code: proto.ErrCodeAuthReqRedirectError, Msg: "[proxy] failed: " + err.Error()}) |
| 163 | return |
| 164 | } |
| 165 | if jobj, err = proto.ParseAuthReply(res); err != nil { |
| 166 | sendErrReply(w, r, &proto.HTTPAuthReply{Code: proto.ErrCodeAuthReqRedirectError, Msg: "Target Server failed: " + err.Error()}) |
| 167 | return |
| 168 | } |
| 169 | sendOkReply(w, r, newSuccessHTTPAuthReply(jobj.Data)) |
| 170 | } else { |
| 171 | m.authProxy.reverseProxy.ServeHTTP(w, r) |
| 172 | } |
| 173 | } |
no test coverage detected