(part *multipart.Part)
| 1806 | } |
| 1807 | |
| 1808 | func readMultipartPart(part *multipart.Part) (multipartPartPayload, error) { |
| 1809 | bodyBytes, err := io.ReadAll(part) |
| 1810 | if err != nil { |
| 1811 | return multipartPartPayload{}, err |
| 1812 | } |
| 1813 | |
| 1814 | contentType := strings.ToLower(strings.TrimSpace(part.Header.Get("Content-Type"))) |
| 1815 | if parsedType, _, err := mime.ParseMediaType(contentType); err == nil { |
| 1816 | contentType = strings.ToLower(strings.TrimSpace(parsedType)) |
| 1817 | } |
| 1818 | |
| 1819 | if isJSONContentType(contentType) { |
| 1820 | bodyBytes = []byte(strings.TrimSpace(string(bodyBytes))) |
| 1821 | } else if strings.HasPrefix(contentType, "text/") || contentType == "application/xml" || contentType == "application/x-ndjson" || contentType == "application/ndjson" { |
| 1822 | normalized := normalizeLineEndings(string(bodyBytes)) |
| 1823 | normalized = strings.TrimSuffix(normalized, "\n") |
| 1824 | bodyBytes = []byte(normalized) |
| 1825 | } |
| 1826 | |
| 1827 | return multipartPartPayload{ |
| 1828 | contentType: contentType, |
| 1829 | body: append([]byte(nil), bodyBytes...), |
| 1830 | }, nil |
| 1831 | } |
| 1832 | |
| 1833 | func compareMultipartPart(expected multipartPartPayload, actual multipartPartPayload, jsonNoiseKeys map[string]struct{}) (bool, string) { |
| 1834 | if expected.contentType != actual.contentType { |
no test coverage detected