Skip to content

Commit

Permalink
correctly serialize MTOM into axios data
Browse files Browse the repository at this point in the history
  • Loading branch information
ischisan committed Nov 12, 2021
1 parent d284fea commit cad5341
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ export class HttpClient implements IHttpClient {
}
}
}
headers['Content-Type'] = 'multipart/related; type="application/xop+xml"; start="<' + start + '>"; start-info="text/xml"; boundary=' + uuidv4();
const boundary = uuidv4();
headers['Content-Type'] = 'multipart/related; type="application/xop+xml"; start="<' + start + '>"; type="text/xml"; boundary=' + boundary;
if (action) {
headers['Content-Type'] = headers['Content-Type'] + '; ' + action;
}
Expand All @@ -119,7 +120,21 @@ export class HttpClient implements IHttpClient {
'body': attachment.body,
});
});
// options.multipart = multipart;
options.data = `--${boundary}\r\n`;

let multipartCount = 0;
multipart.forEach((part) => {
Object.keys(part).forEach((key) => {
if (key !== "body") {
options.data += `${key}: ${part[key]}\r\n`;
}
});
options.data += "\r\n";
options.data += `${part.body}\r\n--${boundary}${
multipartCount === multipart.length - 1 ? "--" : ""
}\r\n`;
multipartCount++;
});
} else {
options.data = data;
}
Expand Down

0 comments on commit cad5341

Please sign in to comment.