Code Monkey home page Code Monkey logo

meros's People

Contributors

0xflotus avatar dependabot[bot] avatar flash-me avatar lukeed avatar maraisr avatar netbrain avatar wincent avatar yaacovcr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

meros's Issues

[feature request] Nested multiparts

As properly stated in the README (caveats) the are some known limitations, from my point of view, Nested multiparts is the more important, as we use to compose components, soon we might get caught in this trap.

@maraisr Do you have something in mind on this topic?

Boundary parser

Describe the bug

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:

ctype.substring(idx_boundary + 9).trim().replace(/['"]/g, '')

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.

To reproduce

Content-Type: multipart/mixed;boundary="-";charset=utf-8 incorrectly leads to a boundary ---;charset=utf-8

Expected behavior

Content-Type: multipart/mixed;boundary="-";charset=utf-8 must lead to a boundary ---

Validations

Example for relay

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,
                      },
                    });
                  }

Implementation broken when upgrading from 1.1.4 to 1.3.0

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?

Unable to parse json with boundary symbols in the response

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?

Emits incorrect results when utf-8 codepoint is split between two chunks

Describe the bug

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.

To reproduce

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 }

Expected behavior

It should decode correctly.

Support callback/observable style API

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.

How to properly mock responses for testing?

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 :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.