Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jtescher
Copy link
Contributor

Pull Request Checklist

  • Have you read How to write the perfect pull request?
  • Have you read through the contributor guidelines?
  • Have you signed the Lightbend CLA?
  • Have you [squashed your commits]? (Optional, but makes merge messages nicer.)
  • Have you added copyright headers to new files?
  • Have you checked that both Scala and Java APIs are updated?
  • Have you updated the documentation for both Scala and Java sections?
  • Have you added tests for any changed functionality?

Purpose

Currently the regular expression in https://github.com/playframework/playframework/blob/2.5.4/framework/src/play/src/main/scala/play/api/mvc/RangeResult.scala#L268-L271 will not match expected range header values.

E.g.

val WithoutEntityLengthRangeSetPattern = """^bytes=([0-9]+-[0-9]+,?)+""".r
val header = "bytes=1-2"

header match {
    case WithoutEntityLengthRangeSetPattern() => ...
    case _ => ...
}

Will incorrectly fall through to case _ => ... even though header.matches(WithoutEntityLengthRangeSetPattern.regex) is true

We need to add a parameter or _ to the case statement as I have in this PR to allow it to successfully match.

header match {
    case WithoutEntityLengthRangeSetPattern(_) => ...
    case _ => ...
}

Will match correctly.

@marcospereira
Copy link
Member

marcospereira commented Jul 15, 2016

@jtescher there is a test failing:

https://travis-ci.org/playframework/playframework/jobs/145093973#L1079

You can run these tests in isolation by executing the following command inside framework directory:

sbt "~ test-only play.api.mvc.Range*"

@jtescher jtescher force-pushed the bugfix/range-result-pattern-match branch 2 times, most recently from 207cb84 to e676e73 Compare July 16, 2016 05:52
@jtescher
Copy link
Contributor Author

@marcospereira the tests should now be passing. I'm not entirely sure what the behavior should be for requesting bytes from streams that do not have a fixed entity length. Current behavior in RangeSet#first seems to be that it will accept the first byte, but ignore the last byte. So if you pass Range: bytes=2-4 you will get the offset of 2, but it will not limit to 4. I haven't read over the spec very clearly so that might be the correct behavior in this case. It's also a little surprising that you can't pass Range: bytes=2- if the entity has no known length but RangeResult#WithoutEntityLengthRangeSetPattern will not match it.

@jtescher jtescher force-pushed the bugfix/range-result-pattern-match branch from e676e73 to 3248e26 Compare July 16, 2016 06:24
@jtescher
Copy link
Contributor Author

@marcospereira thoughts? This PR fixes the matching bug currently. The other issues are greater questions that could probably be addressed in another PR if required.

@marcospereira
Copy link
Member

@jtescher sorry for the delay. I did not had time to look at this PR but I will review it again today at night and let you know if I have any other concerns.

@jtescher
Copy link
Contributor Author

Ok great, thanks a lot

@marcospereira
Copy link
Member

I'm not entirely sure what the behavior should be for requesting bytes from streams that do not have a fixed entity length. Current behavior in RangeSet#first seems to be that it will accept the first byte, but ignore the last byte.

According to RFC 7233, it should use the last-byte-pos or the remainder of the entity:

A client can limit the number of bytes requested without knowing the size of the selected representation. If the last-byte-pos value is absent, or if the value is greater than or equal to the current length of the representation data, the byte range is interpreted as the remainder of the representation (i.e., the server replaces the value of last-byte-pos with a value that is one less than the current length of the selected representation).

This is not the current behavior, but it could be corrected in another PR.


This PR can also be backported to 2.5.x branch.

@jtescher thank you and sorry about the delay.

@marcospereira marcospereira merged commit 172d424 into playframework:master Jul 19, 2016
@marcospereira marcospereira added this to the 2.5.5 milestone Jul 19, 2016
@marcospereira
Copy link
Member

Backport to 2.5.x: e340beb

@jtescher jtescher deleted the bugfix/range-result-pattern-match branch July 19, 2016 04:23
@jtescher
Copy link
Contributor Author

Great, thanks for the review and quick responses!

wsargent pushed a commit to wsargent/playframework that referenced this pull request Oct 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants