id stringlengths 2 7 | text stringlengths 17 51.2k | title stringclasses 1
value |
|---|---|---|
c167800 |
c := AcquireCookie()
c.SetKey(key)
c.SetExpire(CookieExpireDelete)
h.SetCookie(c)
ReleaseCookie(c)
} | |
c167801 | = delAllArgs(h.cookies, key)
} | |
c167802 |
h.collectCookies()
h.cookies = delAllArgs(h.cookies, key)
} | |
c167803 |
h.collectCookies()
h.cookies = h.cookies[:0]
} | |
c167804 | := getHeaderKeyBytes(&h.bufKV, key, h.disableNormalizing)
return h.peek(k)
} | |
c167805 | normalizeHeaderKey(h.bufKV.key, h.disableNormalizing)
return h.peek(h.bufKV.key)
} | |
c167806 |
h.parseRawHeaders()
h.collectCookies()
return peekArgStr(h.cookies, key)
} | |
c167807 | h.collectCookies()
return peekArgBytes(h.cookies, key)
} | |
c167808 | return false
}
cookie.ParseBytes(v)
return true
} | |
c167809 | if err != errNeedMore {
h.resetSkipNormalize()
return err
}
n = r.Buffered() + 1
}
} | |
c167810 | = h.AppendBytes(h.bufKV.value[:0])
return h.bufKV.value
} | |
c167811 |
for i, n := 0, len(h.h); i < n; i++ {
kv := &h.h[i]
if !bytes.Equal(kv.key, strDate) {
dst = appendHeaderLine(dst, kv.key, kv.value)
}
}
n := len(h.cookies)
if n > 0 {
for i := 0; i < n; i++ {
kv := &h.cookies[i]
dst = appendHeaderLine(dst, strSetCookie, kv.value)
}
}
if h.ConnectionClose()... | |
c167812 | err := w.Write(h.Header())
return err
} | |
c167813 | err := w.Write(h.Header())
return int64(n), err
} | |
c167814 | = h.AppendBytes(h.bufKV.value[:0])
return h.bufKV.value
} | |
c167815 | := 0, len(h.h); i < n; i++ {
kv := &h.h[i]
dst = appendHeaderLine(dst, kv.key, kv.value)
}
// there is no need in h.collectCookies() here, since if cookies aren't collected yet,
// they all are located in h.h.
n := len(h.cookies)
if n > 0 {
dst = append(dst, strCookie...)
dst = append(dst, strColonSpace.... | |
c167816 | ctx.Request.Header.DelBytes(strAcceptEncoding)
ServeFile(ctx, path)
} | |
c167817 | fs.once.Do(fs.initRequestHandler)
return fs.h
} | |
c167818 | zeroTime, err
}
fileInfo, err := f.Stat()
f.Close()
if err != nil {
return zeroTime, err
}
return fsModTime(fileInfo.ModTime()), nil
} | |
c167819 | append(c.domain[:0], src.domain...)
c.path = append(c.path[:0], src.path...)
c.httpOnly = src.httpOnly
c.secure = src.secure
c.sameSite = src.sameSite
} | |
c167820 | c.path = normalizePath(c.path, c.buf)
} | |
c167821 | c.path = normalizePath(c.path, c.buf)
} | |
c167822 | append(c.domain[:0], domain...)
} | |
c167823 | = append(c.domain[:0], domain...)
} | |
c167824 |
if expire.IsZero() {
expire = CookieExpireUnlimited
}
return expire
} | |
c167825 | append(c.value[:0], value...)
} | |
c167826 | = append(c.value[:0], value...)
} | |
c167827 | append(c.key[:0], key...)
} | |
c167828 | = append(c.key[:0], key...)
} | |
c167829 | = c.path[:0]
c.httpOnly = false
c.secure = false
c.sameSite = CookieSameSiteDisabled
} | |
c167830 | CookieSameSiteDefaultMode:
dst = append(dst, ';', ' ')
dst = append(dst, strCookieSameSite...)
case CookieSameSiteLaxMode:
dst = append(dst, ';', ' ')
dst = append(dst, strCookieSameSite...)
dst = append(dst, '=')
dst = append(dst, strCookieSameSiteLax...)
case CookieSameSiteStrictMode:
dst = append(ds... | |
c167831 |
c.buf = c.AppendBytes(c.buf[:0])
return c.buf
} | |
c167832 | err := w.Write(c.Cookie())
return int64(n), err
} | |
c167833 | src...)
return c.ParseBytes(c.buf)
} | |
c167834 | kv.value[0] | 0x20 {
case 'l': // "lax"
if caseInsensitiveCompare(strCookieSameSiteLax, kv.value) {
c.sameSite = CookieSameSiteLaxMode
}
case 's': // "strict"
if caseInsensitiveCompare(strCookieSameSiteStrict, kv.value) {
c.sameSite = CookieSameSiteStrictMode
}
}
... | |
c167835 | < n; i++ {
kv := &cookies[i]
dst = append(dst, kv.value...)
if i+1 < n {
dst = append(dst, ';', ' ')
}
}
return dst
} | |
c167836 | time.NewTimer(timeout)
}
t := v.(*time.Timer)
initTimer(t, timeout)
return t
} | |
c167837 | nil, fmt.Errorf("InmemoryListener is already closed: use of closed network connection")
}
close(c.accepted)
return c.conn, nil
} | |
c167838 | close(ln.conns)
ln.closed = true
} else {
err = fmt.Errorf("InmemoryListener is already closed")
}
ln.lock.Unlock()
return err
} | |
c167839 |
if path != "/" && path[len(path)-1] != '/' {
r.Get(path, http.RedirectHandler(path+"/", 301).ServeHTTP)
path += "/"
}
path += "*"
r.Get(path, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fs.ServeHTTP(w, r)
}))
} | |
c167840 | ""
x.routeParams.Keys = x.routeParams.Keys[:0]
x.routeParams.Values = x.routeParams.Values[:0]
x.methodNotAllowed = false
} | |
c167841 | if x.URLParams.Keys[k] == key {
return x.URLParams.Values[k]
}
}
return ""
} | |
c167842 | nil {
return rctx.URLParam(key)
}
return ""
} | |
c167843 | {
return rctx.URLParam(key)
}
return ""
} | |
c167844 | (*s).Values = append((*s).Values, value)
} | |
c167845 |
}
if v, ok := ctx.Value(http.LocalAddrContextKey).(net.Addr); ok {
baseCtx = context.WithValue(baseCtx, http.LocalAddrContextKey, v)
}
h.ServeHTTP(w, r.WithContext(baseCtx))
})
return fn
} | |
c167846 | find a HEAD handler for the routing path, if not found, traverse
// the router as through its a GET route, but proceed with the request
// with the HEAD method.
if !rctx.Routes.Match(tctx, "HEAD", routePath) {
rctx.RouteMethod = "GET"
rctx.RoutePath = routePath
next.ServeHTTP(w, r)
return
}... | |
c167847 | w.Write([]byte("pong"))
} | |
c167848 | if rctx.RoutePath != "" {
path = rctx.RoutePath
} else {
path = r.URL.Path
}
if len(path) > 1 && path[len(path)-1] == '/' {
rctx.RoutePath = path[:len(path)-1]
}
next.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
} | |
c167849 | strings.ToLower(strings.TrimSpace(r.Header.Get("Content-Type")))
if i := strings.Index(s, ";"); i > -1 {
s = s[0:i]
}
for _, t := range cT {
if t == s {
next.ServeHTTP(w, r)
return
}
}
w.WriteHeader(http.StatusUnsupportedMediaType)
}
return http.HandlerFunc(fn)
}
} | |
c167850 | ""
}
if reqID, ok := ctx.Value(RequestIDKey).(string); ok {
return reqID
}
return ""
} | |
c167851 | &ChainHandler{mws, h, chain(mws, h)}
} | |
c167852 | end handler with the middleware chain
h := middlewares[len(middlewares)-1](endpoint)
for i := len(middlewares) - 2; i >= 0; i-- {
h = middlewares[i](h)
}
return h
} | |
c167853 | interface{} {
return NewRouteContext()
}
return mux
} | |
c167854 | // Once the request is finished, reset the routing context and put it back
// into the pool for reuse from another request.
rctx = mx.pool.Get().(*Context)
rctx.Reset()
rctx.Routes = mx
r = r.WithContext(context.WithValue(r.Context(), RouteCtxKey, rctx))
mx.handler.ServeHTTP(w, r)
mx.pool.Put(rctx)
} | |
c167855 | before routes on a mux")
}
mx.middlewares = append(mx.middlewares, middlewares...)
} | |
c167856 | http.Handler) {
mx.handle(mALL, pattern, handler)
} | |
c167857 | http.HandlerFunc) {
mx.handle(mALL, pattern, handlerFn)
} | |
c167858 | method is not supported.", method))
}
mx.handle(m, pattern, handler)
} | |
c167859 | mx.Method(method, pattern, handlerFn)
} | |
c167860 | http.HandlerFunc) {
mx.handle(mCONNECT, pattern, handlerFn)
} | |
c167861 | http.HandlerFunc) {
mx.handle(mDELETE, pattern, handlerFn)
} | |
c167862 | http.HandlerFunc) {
mx.handle(mGET, pattern, handlerFn)
} | |
c167863 | http.HandlerFunc) {
mx.handle(mHEAD, pattern, handlerFn)
} | |
c167864 | http.HandlerFunc) {
mx.handle(mOPTIONS, pattern, handlerFn)
} | |
c167865 | http.HandlerFunc) {
mx.handle(mPATCH, pattern, handlerFn)
} | |
c167866 | http.HandlerFunc) {
mx.handle(mPOST, pattern, handlerFn)
} | |
c167867 | http.HandlerFunc) {
mx.handle(mPUT, pattern, handlerFn)
} | |
c167868 | http.HandlerFunc) {
mx.handle(mTRACE, pattern, handlerFn)
} | |
c167869 | = Chain(mx.middlewares...).HandlerFunc(hFn).ServeHTTP
}
// Update the notFoundHandler from this point forward
m.notFoundHandler = hFn
m.updateSubRoutes(func(subMux *Mux) {
if subMux.notFoundHandler == nil {
subMux.NotFound(hFn)
}
})
} | |
c167870 | Chain(mx.middlewares...).HandlerFunc(hFn).ServeHTTP
}
// Update the methodNotAllowedHandler from this point forward
m.methodNotAllowedHandler = hFn
m.updateSubRoutes(func(subMux *Mux) {
if subMux.methodNotAllowedHandler == nil {
subMux.MethodNotAllowed(hFn)
}
})
} | |
c167871 | == nil {
mx.buildRouteHandler()
}
// Copy middlewares from parent inline muxs
var mws Middlewares
if mx.inline {
mws = make(Middlewares, len(mx.middlewares))
copy(mws, mx.middlewares)
}
mws = append(mws, middlewares...)
im := &Mux{pool: mx.pool, inline: true, parent: mx, tree: mx.tree, middlewares: mws}... | |
c167872 | mx.notFoundHandler != nil {
return mx.notFoundHandler
}
return http.NotFound
} | |
c167873 | return mx.methodNotAllowedHandler
}
return methodNotAllowedHandler
} | |
c167874 | = http.HandlerFunc(mx.routeHTTP)
h = Chain(mx.middlewares...).Handler(handler)
} else {
h = handler
}
// Add the endpoint to the tree and return the node
return mx.tree.InsertRoute(method, pattern, h)
} | |
c167875 | {
mx.MethodNotAllowedHandler().ServeHTTP(w, r)
return
}
// Find the route
if _, _, h := mx.tree.FindRoute(rctx, method, routePath); h != nil {
h.ServeHTTP(w, r)
return
}
if rctx.methodNotAllowed {
mx.MethodNotAllowedHandler().ServeHTTP(w, r)
} else {
mx.NotFoundHandler().ServeHTTP(w, r)
}
} | |
c167876 | mx.tree.routes() {
subMux, ok := r.SubRoutes.(*Mux)
if !ok {
continue
}
fn(subMux)
}
} | |
c167877 | w.WriteHeader(405)
w.Write(nil)
} | |
c167878 | defer func() {
entry.Write(ww.Status(), ww.BytesWritten(), time.Since(t1))
}()
next.ServeHTTP(ww, WithLogEntry(r, entry))
}
return http.HandlerFunc(fn)
}
} | |
c167879 | r.Context().Value(LogEntryCtxKey).(LogEntry)
return entry
} | |
c167880 | r.WithContext(context.WithValue(r.Context(), LogEntryCtxKey, entry))
return r
} | |
c167881 | {
scheme = "https"
}
cW(entry.buf, useColor, nCyan, "%s://%s%s %s\" ", scheme, r.Host, r.RequestURI, r.Proto)
entry.buf.WriteString("from ")
entry.buf.WriteString(r.RemoteAddr)
entry.buf.WriteString(" - ")
return entry
} | |
c167882 | {
if !contentEncoding(r.Header.Get("Content-Type"), charsets...) {
w.WriteHeader(http.StatusUnsupportedMediaType)
return
}
next.ServeHTTP(w, r)
})
}
} | |
c167883 | _, ce = split(ce, "charset=")
ce, _ = split(ce, ";")
for _, c := range charsets {
if ce == c {
return true
}
}
return false
} | |
c167884 | sep, 2)
a = strings.TrimSpace(parts[0])
if len(parts) == 2 {
b = strings.TrimSpace(parts[1])
}
return a, b
} | |
c167885 | position
nn := &node{
typ: ntStatic,
label: search[0],
prefix: search,
}
hn = child.addChild(nn, search)
}
} else if segStartIdx > 0 {
// Route has some param
// starts with a static segment
child.typ = ntStatic
child.prefix = search[:segStartIdx]
child.rex = nil
... | |
c167886 |
xsearch = ""
}
if xn == nil {
continue
}
// did we find it yet?
if len(xsearch) == 0 {
if xn.isLeaf() {
h, _ := xn.endpoints[method]
if h != nil && h.handler != nil {
rctx.routeParams.Keys = append(rctx.routeParams.Keys, h.paramKeys...)
return xn
}
// flag that the routi... | |
c167887 | = dbGetArticleBySlug(articleSlug)
} else {
render.Render(w, r, ErrNotFound)
return
}
if err != nil {
render.Render(w, r, ErrNotFound)
return
}
ctx := context.WithValue(r.Context(), "article", article)
next.ServeHTTP(w, r.WithContext(ctx))
})
} | |
c167888 | {
render.RenderList(w, r, NewArticleListResponse(articles))
} | |
c167889 | render.Render(w, r, ErrInvalidRequest(err))
return
}
article := data.Article
dbNewArticle(article)
render.Status(r, http.StatusCreated)
render.Render(w, r, NewArticleResponse(article))
} | |
c167890 | // middleware. The worst case, the recoverer middleware will save us.
article := r.Context().Value("article").(*Article)
if err := render.Render(w, r, NewArticleResponse(article)); err != nil {
render.Render(w, r, ErrRender(err))
return
}
} | |
c167891 |
}
article = data.Article
dbUpdateArticle(article.ID, article)
render.Render(w, r, NewArticleResponse(article))
} | |
c167892 | article, err = dbRemoveArticle(article.ID)
if err != nil {
render.Render(w, r, ErrInvalidRequest(err))
return
}
render.Render(w, r, NewArticleResponse(article))
} | |
c167893 | http.ResponseWriter, r *http.Request) {
w.Write([]byte("admin: list accounts.."))
})
r.Get("/users/{userId}", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(fmt.Sprintf("admin: view user id %v", chi.URLParam(r, "userId"))))
})
return r
} | |
c167894 | {
http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
return
}
next.ServeHTTP(w, r)
})
} | |
c167895 | // the page number, or the limit, and send a query cursor down the chain
next.ServeHTTP(w, r)
})
} | |
c167896 | reveal the actual error message,
// instead we can transform the message something more friendly or mapped
// to some code / language, etc.
render.DefaultResponder(w, r, render.M{"status": "error"})
return
}
render.DefaultResponder(w, r, v)
}
} | |
c167897 | try it
// both ways, first looking for zlib headers.
// Quote by Mark Adler: http://stackoverflow.com/a/9186091/385548
//
// The list of browsers having problems is quite big, see:
// http://zoompf.com/blog/2012/02/lose-the-wait-http-compression
// https://web.archive.org/web/20120321182910/http://www.vervestudi... | |
c167898 |
ResponseWriter: w,
w: w,
contentTypes: c.allowedTypes,
encoding: encoding,
}
if encoder != nil {
cw.w = encoder
}
// Re-add the encoder to the pool if applicable.
defer cleanup()
defer cw.Close()
next.ServeHTTP(cw, r)
}
return http.HandlerFunc(fn)
}
... | |
c167899 | {
pool.Put(encoder)
}
encoder.Reset(w)
return encoder, name, cleanup
}
if fn, ok := c.encoders[name]; ok {
return fn(w, c.level), name, func() {}
}
}
}
// No encoder found to match the accepted encoding
return nil, "", func() {}
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.