MCPcopy
hub / github.com/keploy/keploy / readMultipartPart

Function readMultipartPart

pkg/util.go:1808–1831  ·  view source on GitHub ↗
(part *multipart.Part)

Source from the content-addressed store, hash-verified

1806}
1807
1808func 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
1833func compareMultipartPart(expected multipartPartPayload, actual multipartPartPayload, jsonNoiseKeys map[string]struct{}) (bool, string) {
1834 if expected.contentType != actual.contentType {

Callers 2

compareMultipartStreamFunction · 0.85
parseMultipartQueueBytesFunction · 0.85

Calls 3

isJSONContentTypeFunction · 0.85
normalizeLineEndingsFunction · 0.85
GetMethod · 0.65

Tested by

no test coverage detected