MCPcopy Create free account
hub / github.com/kataras/iris / PostValues

Method PostValues

context/context.go:1894–1933  ·  view source on GitHub ↗

PostValues returns all the parsed form data from POST, PATCH, or PUT body parameters based on a "name" as a string slice. The default form's memory maximum size is 32MB, it can be changed by the `iris#WithPostMaxMemory` configurator at main configuration passed on `app.Run`'s second argument. In a

(name string)

Source from the content-addressed store, hash-verified

1892// Look ErrEmptyForm, ErrNotFound and ErrEmptyFormField respectfully.
1893// See `PostValueMany` method too.
1894func (ctx *Context) PostValues(name string) ([]string, error) {
1895 _, ok := ctx.form()
1896 if !ok {
1897 if !ctx.app.ConfigurationReadOnly().GetFireEmptyFormError() {
1898 return nil, nil
1899 }
1900
1901 return nil, ErrEmptyForm // empty form.
1902 }
1903
1904 values, ok := ctx.request.PostForm[name]
1905 if !ok {
1906 return nil, ErrNotFound // field does not exist
1907 }
1908
1909 if len(values) == 0 ||
1910 // Fast check for its first empty value (see below).
1911 strings.TrimSpace(values[0]) == "" {
1912 return nil, fmt.Errorf("%w: %s", ErrEmptyFormField, name)
1913 }
1914
1915 for _, value := range values {
1916 if value == "" { // if at least one empty value, then perform the strip from the beginning.
1917 result := make([]string, 0, len(values))
1918 for _, value := range values {
1919 if strings.TrimSpace(value) != "" {
1920 result = append(result, value) // we store the value as it is, not space-trimmed.
1921 }
1922 }
1923
1924 if len(result) == 0 {
1925 return nil, fmt.Errorf("%w: %s", ErrEmptyFormField, name)
1926 }
1927
1928 return result, nil
1929 }
1930 }
1931
1932 return values, nil
1933}
1934
1935// PostValueMany is like `PostValues` method, it returns the post data of a given key.
1936// In addition to `PostValues` though, the returned value is a single string

Callers 3

PostValueManyMethod · 0.95
PostValueDefaultMethod · 0.95
PostValueStringMethod · 0.95

Calls 4

formMethod · 0.95
ErrorfMethod · 0.80
GetFireEmptyFormErrorMethod · 0.65
ConfigurationReadOnlyMethod · 0.65

Tested by

no test coverage detected