MCPcopy Index your code
hub / github.com/SenseUnit/dumbproxy / HandleGetRandom

Method HandleGetRandom

handler/handler.go:202–219  ·  view source on GitHub ↗
(wr http.ResponseWriter, req *http.Request, username string)

Source from the content-addressed store, hash-verified

200}
201
202func (s *ProxyHandler) HandleGetRandom(wr http.ResponseWriter, req *http.Request, username string) {
203 if len(req.URL.Path) <= 1 || req.URL.Path[0] != '/' {
204 http.Error(wr, "Incorrect requested random data length", http.StatusBadRequest)
205 }
206 length, err := strconv.ParseInt(req.URL.Path[1:], 10, 64)
207 if err != nil || length < 0 {
208 http.Error(wr, "Incorrect requested random data length", http.StatusBadRequest)
209 }
210 var seed [32]byte
211 binary.NativeEndian.PutUint64(seed[0:], rand.Uint64())
212 binary.NativeEndian.PutUint64(seed[8:], rand.Uint64())
213 binary.NativeEndian.PutUint64(seed[16:], rand.Uint64())
214 binary.NativeEndian.PutUint64(seed[24:], rand.Uint64())
215 rng := rand.NewChaCha8(seed)
216 wr.Header().Set("Content-Length", strconv.FormatInt(length, 10))
217 wr.WriteHeader(http.StatusOK)
218 io.Copy(wr, io.LimitReader(rng, length))
219}
220
221func (s *ProxyHandler) isLoopback(req *http.Request) (string, bool) {
222 s.outboundMux.RLock()

Callers 1

ServeHTTPMethod · 0.95

Calls 2

ErrorMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected