Skip to content

Conversation

@maciejmrozinski
Copy link

Varnish Cache returns data with chunk size lead by 2 zeros 00. Examples:

00e instead of e
001 instead of 1
001234 instead of 1234

Leading zeros have no value so we can trim them. I'm not 100% sure that there are always 2 zeros, but as far as I observed, there was 2 (to be sure I trim them all). Last zero is passed normally, so \r\n0\r\n\r\n.

Tests added.

@WyriHaximus WyriHaximus added this to the v0.4.16 milestone Feb 28, 2017
Copy link
Member

@WyriHaximus WyriHaximus left a comment

Choose a reason for hiding this comment

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

Nice catch 👍 !

'varnish-type-response-extra-line' => [
["006\r\nWi\r\nki\r\n005\r\npedia\r\n00e\r\n in\r\n\r\nchunks.\r\n0\r\n\r\n"],
"Wi\r\nkipedia in\r\n\r\nchunks."
]
Copy link
Member

Choose a reason for hiding this comment

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

While the ltrim will definitely handle multiple leading 0's, could you add examples with more and less leading 0's then two. Just to ensure we don't accidentally refactor it specifically to two in the future. (You could even add a test adding a random number of 0's.)

Copy link
Author

Choose a reason for hiding this comment

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

Done

@WyriHaximus WyriHaximus requested review from clue and jsor February 28, 2017 15:41
Copy link
Member

@clue clue left a comment

Choose a reason for hiding this comment

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

Nice catch! 👍 This actually appears to be valid according to the RFC: https://tools.ietf.org/html/rfc7230#section-4.1

May I ask you to test this also for the end chunk?

Also ping @legionth for the reference, who added a somewhat similar decoder for our Http component 👍

@maciejmrozinski
Copy link
Author

I added tests for end 0 chunk length, but as a invalid ones. According to RFC last 0 should be only one.

@clue
Copy link
Member

clue commented Feb 28, 2017

Thanks for your quick response! 👍 It's actually tempting to confuse ABNF syntax with PCRE modifiers, the RFC linked above uses an ABNF for this that is defined as last-chunk = 1*("0")…. In other words, it actually allows any number (1+) of zeros here. (See also https://tools.ietf.org/html/rfc5234#section-3.6 for more details about the ABNF.)

@maciejmrozinski
Copy link
Author

Sorry about that, I didn't know about this ABNF. I took the code from @legionth and moved tests to valid ones.

Copy link
Member

@clue clue left a comment

Choose a reason for hiding this comment

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

Nice, thanks your quick response! 👍

@clue clue added the bug label Mar 1, 2017
@WyriHaximus WyriHaximus merged commit 3a90b2a into reactphp:master Mar 1, 2017
@WyriHaximus
Copy link
Member

Awesome and thank you 👍 . I'll tag a new release soon :shipit:

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.

4 participants