maraisr / meros Goto Github PK
View Code? Open in Web Editor NEW🪢 A fast utility that makes reading multipart responses simple
License: MIT License
🪢 A fast utility that makes reading multipart responses simple
License: MIT License
This Content-Type: multipart/mixed;boundary="-";charset=utf-8
leads to the following wrong boundary ---;charset=utf-8
.
The shape is "Content-Type" ":" type "/" subtype *(";" parameter)
from RFC 1521 page 69.
The code involved is related to the calculation of the boundary:
Line 105 in 183f788
It could be fixed looking ahead for the ;
and removing anything after:
ctype.substring(idx_boundary + 9).replace(/;.*/g, '').trim().replace(/['"]/g, '')
Please let me know if you handle the fix or if I should PR this little change.
Note: meros
is used in our client Banana Cake Pop
. @maraisr Thanks for your support to the OSS.
Content-Type: multipart/mixed;boundary="-";charset=utf-8
incorrectly leads to a boundary ---;charset=utf-8
Content-Type: multipart/mixed;boundary="-";charset=utf-8
must lead to a boundary ---
The final part contains just a line-break and triggers the error in the example (or when ported as the example shows).
I guess that this part should be filtered.
body: "\r\n"
json: false
Also, should not be removed the assertion independently of the hasNext
value?
Or something like:
if (data) {
sink.next({
data,
path,
label,
extensions: {
is_final: !hasNext,
},
});
} else {
sink.next({
data: null,
extensions: {
is_final: !hasNext,
},
});
}
Hi,
I am currently using 1.1.4 and would like to upgrade to 1.3.0, but the library is not working as expected after the upgrade and I have been unable to isolate the issue through debugging the library... and was hoping you could help.
I am using the browser version of the library like below:
import { meros } from 'meros/browser';
const fetchResult = await fetch(url, {
body: JSON.stringify(body),
headers: new Headers(this._headers),
method: 'POST',
}).then(meros);
And I am generating the chunked response for my test like below:
export const createResponseChunks = (responses: PlainObject[]) => {
const chunks = responses.map(response => {
const chunk = Buffer.from(JSON.stringify(response), 'utf8');
return [
'',
'---',
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' + String(chunk.length),
'',
chunk,
'',
].join('\r\n');
});
return `${chunks.join('')}\r\n-----\r\n`;
};
This works fine with 1.1.4. From going through your code/commit history I can see you have made some changes to how you deal with \r\n'
, but I have not been able to refactor the above test code in a way that I can get it working with the library.
Any chance you can guide me as to how I need to format the output of createResponseChunks
to get it working with the library?
Requesting to add tags to your repository .
I'm using meros with relay for the @defer
feature and by a coincidence we got exactly ---
symbols in a particular field of received json, which leads to a parse error, because part.json
is false.
Of course we can just remove these symbols from the data, but maybe there is a better way to handle it in the library?
meros does not correctly decode utf-8 encoded data which is yielded in a different chunk.
You need to pass { stream: true }
to TextDecoder#decode
:
https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/decode#options
Furthermore, you may not share instances of the encoder between streams since this is a stateful object. If you share instances then multiple concurrent streams will impact each other.
const stream = async function*() {
const smiley = Buffer.from("🤔");
yield Buffer.from("\r\n---\r\n\r\n");
yield smiley.subarray(0, 2);
yield smiley.subarray(2);
yield Buffer.from("\r\n-----\r\n");
}();
const chunks = await meros(new Response(stream, {
headers: {
"content-type": 'multipart/mixed; boundary="-"',
},
}));
await Promise.all([
async function() {
for await (const chunk of chunks) {
console.log(chunk);
}
}(),
]);
Output:
{ headers: {}, body: '���', json: false }
It should decode correctly.
As per discussions on Discord, it'd be nice to have a callback/observable style API in meros
, for cases where using async iterators etc aren't possible/desirable. Adding a ticket here to track that.
It's more of a question or a documentation suggestion than a solid issue, hopefully that's OK for you.
I'm writing a Node.js application in which I'd like to process multipart response using meros
. I'm using WHATWG fetch
provided with Node, so I'm interested in meros/browser
.
To ensure I'm processing the data correctly I'd like to make a test suite in which I'll provide some responses and check if I'm happy with the final result.
The problem is I don't know how to properly create Response
objects for such a test suite. I've tried running the basic example from your repo and using the response body in new Response
constructor. The solution seems to be working correctly for methods like res.text()
. The problem is that in that case the async generator returned by meros
does not yield anything.
Here is the snippet: https://stackblitz.com/edit/vitejs-vite-9mzij1?file=main.js. It runs in the browser to ensure that my problems are not caused by using browser library in Node.js.
Could you please provide some hint? Thanks in advance :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.