MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / parse_part

Function parse_part

app/server/multipart.cpp:65–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65MultipartPart parse_part(const std::string & segment) {
66 MultipartPart part;
67 size_t header_end = segment.find("\r\n\r\n");
68 size_t separator_len = 4;
69 if (header_end == std::string::npos) {
70 header_end = segment.find("\n\n");
71 separator_len = 2;
72 }
73 if (header_end == std::string::npos) {
74 return part;
75 }
76
77 part.data = segment.substr(header_end + separator_len);
78
79 std::istringstream header_stream(segment.substr(0, header_end));
80 std::string line;
81 while (std::getline(header_stream, line)) {
82 if (!line.empty() && line.back() == '\r') {
83 line.pop_back();
84 }
85 const auto colon = line.find(':');
86 if (colon == std::string::npos) {
87 continue;
88 }
89 const std::string key = lower_ascii(trim(line.substr(0, colon)));
90 const std::string value = trim(line.substr(colon + 1));
91 if (key == "content-disposition") {
92 part.name = extract_header_param(value, "name");
93 part.filename = extract_header_param(value, "filename");
94 }
95 }
96 return part;
97}
98
99} // namespace
100

Callers 1

parse_multipart_bodyFunction · 0.85

Calls 5

extract_header_paramFunction · 0.85
lower_asciiFunction · 0.70
trimFunction · 0.70
findMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected