MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / handleMuxHttpConn

Function handleMuxHttpConn

core/server/server.go:171–215  ·  view source on GitHub ↗
(conn net.Conn)

Source from the content-addressed store, hash-verified

169}
170
171func handleMuxHttpConn(conn net.Conn) {
172 defer conn.Close()
173
174 req, err := http.ReadRequest(bufio.NewReader(conn))
175 if err != nil {
176 return
177 }
178
179 if req.Host == "" {
180 return
181 }
182
183 ua := req.Header.Get("User-Agent")
184 if ua == "" {
185 return
186 }
187
188 switch req.Method {
189 case http.MethodGet, http.MethodHead, http.MethodPost:
190 default:
191 return
192 }
193
194 if len(req.RequestURI) > 4096 {
195 return
196 }
197
198 if !strings.HasPrefix(req.URL.Path, "/") {
199 return
200 }
201
202 target := "https://" + req.Host + req.URL.RequestURI()
203
204 resp := &http.Response{
205 StatusCode: http.StatusTemporaryRedirect,
206 Proto: "HTTP/1.1",
207 ProtoMajor: 1,
208 ProtoMinor: 1,
209 Header: make(http.Header),
210 }
211 resp.Header.Set("Location", target)
212 resp.Header.Set("Connection", "close")
213
214 _ = resp.Write(conn)
215}

Callers 1

StartFunction · 0.85

Calls 4

CloseMethod · 0.65
GetMethod · 0.65
SetMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected