GetForm returns the request form (url queries, post or multipart) values.
(r *http.Request, postMaxMemory int64, resetBody bool)
| 1810 | |
| 1811 | // GetForm returns the request form (url queries, post or multipart) values. |
| 1812 | func GetForm(r *http.Request, postMaxMemory int64, resetBody bool) (form map[string][]string, found bool) { |
| 1813 | /* |
| 1814 | net/http/request.go#1219 |
| 1815 | for k, v := range f.Value { |
| 1816 | r.Form[k] = append(r.Form[k], v...) |
| 1817 | // r.PostForm should also be populated. See Issue 9305. |
| 1818 | r.PostForm[k] = append(r.PostForm[k], v...) |
| 1819 | } |
| 1820 | */ |
| 1821 | |
| 1822 | if form := r.Form; len(form) > 0 { |
| 1823 | return form, true |
| 1824 | } |
| 1825 | |
| 1826 | if form := r.PostForm; len(form) > 0 { |
| 1827 | return form, true |
| 1828 | } |
| 1829 | |
| 1830 | if m := r.MultipartForm; m != nil { |
| 1831 | if len(m.Value) > 0 { |
| 1832 | return m.Value, true |
| 1833 | } |
| 1834 | } |
| 1835 | |
| 1836 | if resetBody { |
| 1837 | // on POST, PUT and PATCH it will read the form values from request body otherwise from URL queries. |
| 1838 | if m := r.Method; m == "POST" || m == "PUT" || m == "PATCH" { |
| 1839 | body, restoreBody, err := GetBody(r, resetBody) |
| 1840 | if err != nil { |
| 1841 | return nil, false |
| 1842 | } |
| 1843 | setBody(r, body) // so the ctx.request.Body works |
| 1844 | defer restoreBody() // so the next GetForm calls work. |
| 1845 | |
| 1846 | // r.Body = io.NopCloser(io.TeeReader(r.Body, buf)) |
| 1847 | } else { |
| 1848 | resetBody = false |
| 1849 | } |
| 1850 | } |
| 1851 | |
| 1852 | // ParseMultipartForm calls `request.ParseForm` automatically |
| 1853 | // therefore we don't need to call it here, although it doesn't hurt. |
| 1854 | // After one call to ParseMultipartForm or ParseForm, |
| 1855 | // subsequent calls have no effect, are idempotent. |
| 1856 | err := r.ParseMultipartForm(postMaxMemory) |
| 1857 | // if resetBody { |
| 1858 | // r.Body = io.NopCloser(bytes.NewBuffer(bodyCopy)) |
| 1859 | // } |
| 1860 | if err != nil && err != http.ErrNotMultipart { |
| 1861 | return nil, false |
| 1862 | } |
| 1863 | |
| 1864 | if form := r.Form; len(form) > 0 { |
| 1865 | return form, true |
| 1866 | } |
| 1867 | |
| 1868 | if form := r.PostForm; len(form) > 0 { |
| 1869 | return form, true |
no test coverage detected
searching dependent graphs…