ezelkow1 commented on code in PR #7161: URL: https://github.com/apache/trafficcontrol/pull/7161#discussion_r1010609907
########## test/fakeOrigin/dtp/handler.go: ########## @@ -0,0 +1,360 @@ +package dtp + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import ( + "crypto/md5" + "encoding/base64" + "encoding/hex" + "fmt" + "io" + "net/http" + "net/url" + "strconv" + "strings" + "time" +) + +const XDtpHdrStr = `X-Dtp` +const XDtpCcHdrStr = `X-Dtp-Cc` + +type DTPHandler struct{} + +func NewDTPHandler() DTPHandler { + return DTPHandler{} +} + +// This is for content generation +type Generator interface { + ContentType() string + io.ReadSeeker +} + +type NewGeneratorFunc func( + map[string]string, + int64, +) Generator + +var GlobalGeneratorFuncs = map[string]NewGeneratorFunc{} + +// No content generation +type HandlerFunc func( + http.ResponseWriter, + *http.Request, + map[string]string, +) + +var GlobalHandlerFuncs = map[string]HandlerFunc{} + +type NewForwardFunc func( + http.ResponseWriter, + *http.Request, + Generator, + map[string]string, + int64, +) Generator + +var GlobalForwarderFuncs = map[string]NewForwardFunc{} + +/* +func timeoutAndDrop(w http.ResponseWriter, r *http.Request, durstr string) { + hj, ok := w.(http.Hijacker) + if !ok { + http.Error(w, "webserver doesn't support hijacking", http.StatusInternalServerError) + DebugLogf("Can't get a hijack\n") + return + } + + conn, buf, err := hj.Hijack() + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + DebugLogf("hijack failed: %s\n", err) + return + } + + delaydur, err := time.ParseDuration(durstr) + if err == nil { + if 0 < delaydur { + time.Sleep(delaydur) + } + } + + conn.Close() +} +*/ Review Comment: yes, I think this is something @traeak had worked on adding, but there were some issues with it and it wasnt completely necessary so for now its commented out ########## test/fakeOrigin/dtp/handler.go: ########## @@ -0,0 +1,360 @@ +package dtp + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import ( + "crypto/md5" + "encoding/base64" + "encoding/hex" + "fmt" + "io" + "net/http" + "net/url" + "strconv" + "strings" + "time" +) + +const XDtpHdrStr = `X-Dtp` +const XDtpCcHdrStr = `X-Dtp-Cc` + +type DTPHandler struct{} + +func NewDTPHandler() DTPHandler { + return DTPHandler{} +} + +// This is for content generation +type Generator interface { + ContentType() string + io.ReadSeeker +} + +type NewGeneratorFunc func( + map[string]string, + int64, +) Generator + +var GlobalGeneratorFuncs = map[string]NewGeneratorFunc{} + +// No content generation +type HandlerFunc func( + http.ResponseWriter, + *http.Request, + map[string]string, +) + +var GlobalHandlerFuncs = map[string]HandlerFunc{} + +type NewForwardFunc func( + http.ResponseWriter, + *http.Request, + Generator, + map[string]string, + int64, +) Generator + +var GlobalForwarderFuncs = map[string]NewForwardFunc{} + +/* +func timeoutAndDrop(w http.ResponseWriter, r *http.Request, durstr string) { + hj, ok := w.(http.Hijacker) + if !ok { + http.Error(w, "webserver doesn't support hijacking", http.StatusInternalServerError) + DebugLogf("Can't get a hijack\n") + return + } + + conn, buf, err := hj.Hijack() + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + DebugLogf("hijack failed: %s\n", err) + return + } + + delaydur, err := time.ParseDuration(durstr) + if err == nil { + if 0 < delaydur { + time.Sleep(delaydur) + } + } + + conn.Close() +} +*/ + +func (h DTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + var cmds []string + + /* + if GlobalConfig.Drop { + DebugLogf("Dropping request for '%s'\n", r.URL.String()) + timeoutAndDrop(w, r, "60s") + return + } + */ Review Comment: same as the other one and related to it -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
