(t *testing.T)
| 151 | } |
| 152 | |
| 153 | func testH2ToH2CStreamServeH2C(t *testing.T) *http.Server { |
| 154 | h2s := &http2.Server{} |
| 155 | handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 156 | rstring, err := httputil.DumpRequest(r, false) |
| 157 | if err == nil { |
| 158 | t.Logf("h2c server received req: %s", rstring) |
| 159 | } |
| 160 | // We only accept HTTP/2! |
| 161 | if r.ProtoMajor != 2 { |
| 162 | t.Error("Not an HTTP/2 request, rejected!") |
| 163 | w.WriteHeader(http.StatusInternalServerError) |
| 164 | return |
| 165 | } |
| 166 | |
| 167 | if r.Host != "127.0.0.1:9443" { |
| 168 | t.Errorf("r.Host doesn't match, %v!", r.Host) |
| 169 | w.WriteHeader(http.StatusNotFound) |
| 170 | return |
| 171 | } |
| 172 | |
| 173 | if !strings.HasPrefix(r.URL.Path, "/tov2ray") { |
| 174 | w.WriteHeader(http.StatusNotFound) |
| 175 | return |
| 176 | } |
| 177 | |
| 178 | w.Header().Set("Cache-Control", "no-store") |
| 179 | w.WriteHeader(200) |
| 180 | http.NewResponseController(w).Flush() |
| 181 | |
| 182 | buf := make([]byte, 4*1024) |
| 183 | |
| 184 | for { |
| 185 | n, err := r.Body.Read(buf) |
| 186 | if n > 0 { |
| 187 | w.Write(buf[:n]) |
| 188 | } |
| 189 | |
| 190 | if err != nil { |
| 191 | if err == io.EOF { |
| 192 | r.Body.Close() |
| 193 | } |
| 194 | break |
| 195 | } |
| 196 | } |
| 197 | }) |
| 198 | |
| 199 | server := &http.Server{ |
| 200 | Addr: "127.0.0.1:54321", |
| 201 | Handler: h2c.NewHandler(handler, h2s), |
| 202 | } |
| 203 | return server |
| 204 | } |
| 205 | |
| 206 | // (see https://github.com/caddyserver/caddy/issues/3606 for use case) |
| 207 | func TestH2ToH1ChunkedResponse(t *testing.T) { |
no test coverage detected