(boundary, parts)
| 32 | } |
| 33 | |
| 34 | function buildMultipartBody(boundary, parts) { |
| 35 | const segments = []; |
| 36 | for (const part of parts) { |
| 37 | segments.push(`--${boundary}\r\n`); |
| 38 | if (part.filename) { |
| 39 | segments.push( |
| 40 | `Content-Disposition: form-data; name="${part.name}"; filename="${part.filename}"\r\n` |
| 41 | ); |
| 42 | segments.push(`Content-Type: ${part.contentType || 'application/octet-stream'}\r\n\r\n`); |
| 43 | segments.push(part.data); |
| 44 | } else { |
| 45 | segments.push(`Content-Disposition: form-data; name="${part.name}"\r\n\r\n`); |
| 46 | segments.push(part.value); |
| 47 | } |
| 48 | segments.push('\r\n'); |
| 49 | } |
| 50 | segments.push(`--${boundary}--\r\n`); |
| 51 | return Buffer.concat(segments.map(s => (typeof s === 'string' ? Buffer.from(s) : s))); |
| 52 | } |
| 53 | |
| 54 | describe('Cloud Code Multipart', () => { |
| 55 | it('should not reject multipart requests at the JSON parser level', async () => { |
no outgoing calls
no test coverage detected