MCPcopy
hub / github.com/gofiber/fiber / FormValue

Method FormValue

req.go:373–396  ·  view source on GitHub ↗

FormValue returns the first value by key from a MultipartForm. Search is performed in QueryArgs, PostArgs, MultipartForm and FormFile in this particular order. Defaults to the empty string "" if the form value doesn't exist. If a default value is given, it will return that value if the form value do

(key string, defaultValue ...string)

Source from the content-addressed store, hash-verified

371// When the request is a multipart form, it is parsed using the application's
372// BodyLimit so the configured limit is consistently enforced.
373func (r *DefaultReq) FormValue(key string, defaultValue ...string) string {
374 if r.c.IsMultipart() {
375 // For multipart requests, parse the form using the application's BodyLimit.
376 // fasthttp's FormValue would otherwise re-parse with its default 8 MiB limit,
377 // effectively bypassing the configured BodyLimit.
378 //
379 // Preserve the original search order: QueryArgs → PostArgs → MultipartForm.
380 if v := r.c.fasthttp.QueryArgs().Peek(key); len(v) > 0 {
381 return r.c.app.toString(v)
382 }
383 if v := r.c.fasthttp.PostArgs().Peek(key); len(v) > 0 {
384 return r.c.app.toString(v)
385 }
386 mf, err := r.MultipartForm()
387 if err != nil {
388 return defaultString("", defaultValue)
389 }
390 if vals := mf.Value[key]; len(vals) > 0 {
391 return vals[0]
392 }
393 return defaultString("", defaultValue)
394 }
395 return defaultString(r.c.app.toString(r.c.fasthttp.FormValue(key)), defaultValue)
396}
397
398// Fresh returns true when the response is still “fresh” in the client's cache,
399// otherwise false is returned to indicate that the client cache is now stale

Callers

nothing calls this directly

Calls 5

MultipartFormMethod · 0.95
defaultStringFunction · 0.85
toStringMethod · 0.80
IsMultipartMethod · 0.65
FormValueMethod · 0.65

Tested by

no test coverage detected