Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware to decode encoding and charset #156

Merged
merged 1 commit into from
Apr 21, 2016
Merged

Conversation

arteymix
Copy link
Member

@arteymix arteymix commented Feb 7, 2016

Two really useful middlewares to decode applied encoding and content charset.

It will require some documentation and tests. The logic is quite tricky, especially for decode as remaining encodings are reversed back in the headers.

I couldn't find anything more appropriate than 501 Not Implemented to indicate the lack of support for an encoding or charset.

The typical use case is on the top of an app or for an upload processing:

app.use (decode ()));

app.post ("document", decode ())
    .then ((req, res) => {
        var doc = req.flatten_bytes ();
    });

The squash integration must be opt-in with fallback on the basic converters.

@arteymix arteymix added this to the 0.3.0 milestone Feb 7, 2016
@arteymix arteymix self-assigned this Feb 7, 2016
@arteymix arteymix force-pushed the decode-middlewares branch 2 times, most recently from b7338bd to d0d1b04 Compare February 7, 2016 06:15
@arteymix arteymix force-pushed the decode-middlewares branch 2 times, most recently from f539fce to 6a22513 Compare March 27, 2016 22:31
@arteymix arteymix force-pushed the decode-middlewares branch 4 times, most recently from 2c4834c to 32fcd73 Compare April 20, 2016 23:54
The 'decode' middleware unapply various codings specified in
'Content-Encoding' headers.

It's also possible to forward remaining encodings instead of simply
raising a '501 Not Implemented'.

Provide tests and documentation.
@arteymix arteymix force-pushed the decode-middlewares branch from 32fcd73 to 0429bc6 Compare April 20, 2016 23:59
for (unowned SList<string> encoding = encodings; encoding != null; encoding = encoding.next) {
switch (encoding.data.down ()) {
case "gzip":
case "x-gzip":
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to peek the gzip header and figure out the size if it's available.

@arteymix
Copy link
Member Author

Looks good to me.

Two things:

  • work out charset decoding in a separate PR if it's worth it
  • open feature requests for other codings and a possible Squash integration

@arteymix arteymix merged commit 931050c into master Apr 21, 2016
@arteymix arteymix deleted the decode-middlewares branch April 21, 2016 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant