| 169 | } |
| 170 | |
| 171 | func 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 | } |