MCPcopy
hub / github.com/MetaCubeX/mihomo / ServeHTTP

Method ServeHTTP

transport/xhttp/server.go:227–498  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

225}
226
227func (h *requestHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
228 path := h.config.NormalizedPath()
229 if h.httpHandler != nil && !strings.HasPrefix(r.URL.Path, path) {
230 h.httpHandler.ServeHTTP(w, r)
231 return
232 }
233
234 if h.config.Host != "" && !equalHost(r.Host, h.config.Host) {
235 http.NotFound(w, r)
236 return
237 }
238
239 if !strings.HasPrefix(r.URL.Path, path) {
240 http.NotFound(w, r)
241 return
242 }
243
244 h.config.WriteResponseHeader(w, r.Method, r.Header)
245 length := h.xPaddingBytes.Rand()
246 config := XPaddingConfig{Length: length}
247
248 if h.config.XPaddingObfsMode {
249 config.Placement = XPaddingPlacement{
250 Placement: h.config.XPaddingPlacement,
251 Key: h.config.XPaddingKey,
252 Header: h.config.XPaddingHeader,
253 }
254 config.Method = PaddingMethod(h.config.XPaddingMethod)
255 } else {
256 config.Placement = XPaddingPlacement{
257 Placement: PlacementHeader,
258 Header: "X-Padding",
259 }
260 }
261
262 h.config.ApplyXPaddingToResponse(w, config)
263
264 if r.Method == "OPTIONS" {
265 w.WriteHeader(http.StatusOK)
266 return
267 }
268
269 paddingValue, _ := h.config.ExtractXPaddingFromRequest(r, h.config.XPaddingObfsMode)
270 if !h.config.IsPaddingValid(paddingValue, h.xPaddingBytes.Min, h.xPaddingBytes.Max, PaddingMethod(h.config.XPaddingMethod)) {
271 http.Error(w, "invalid xpadding", http.StatusBadRequest)
272 return
273 }
274 sessionId, seqStr := h.config.ExtractMetaFromRequest(r, path)
275
276 var currentSession *httpSession
277 if sessionId != "" {
278 currentSession = h.upsertSession(sessionId)
279 }
280
281 // stream-up upload: POST /path/{session}
282 if r.Method != http.MethodGet && sessionId != "" && seqStr == "" && h.allowStreamUpUpload() {
283 httpSC := newHTTPServerConn(w, r.Body)
284 err := currentSession.uploadQueue.Push(Packet{

Callers 13

NewServerHandlerFunction · 0.45
parseProviderNameFunction · 0.45
findProviderByNameFunction · 0.45
findProviderProxyByNameFunction · 0.45
parseRuleProviderNameFunction · 0.45
findRuleProviderByNameFunction · 0.45
routerFunction · 0.45
authenticationFunction · 0.45
parseProxyNameFunction · 0.45
findProxyByNameFunction · 0.45
limitBodyFunction · 0.45

Calls 15

upsertSessionMethod · 0.95
allowStreamUpUploadMethod · 0.95
allowPacketUpUploadMethod · 0.95
allowSessionDownloadMethod · 0.95
markConnectedMethod · 0.95
deleteSessionMethod · 0.95
CloseMethod · 0.95
allowStreamOneMethod · 0.95
SetAddrFromRequestFunction · 0.92
equalHostFunction · 0.85
PaddingMethodTypeAlias · 0.85
newHTTPServerConnFunction · 0.85

Tested by 1