Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Add custom Content-Range unit names. #618

wants to merge 1 commit into from

3 participants


This pull request contains some code to allow the user to set a custom Content-Range name.
Typically, the HTTP/1.1 protocol expects the "bytes" keyword in a Content-Range, e.g.
Content-Range: bytes 0-32/128

Some Web-Frameworks like Dojo expect another Range-Unit. It is specified by the HTTP protocol to use custom units for Content-Ranges:

The documentation of Dojo says:

"The server should respond with a Content-Range header to indicate how many items are being returned and how many total items exist:
Content-Range: items 0-24/66"


Looks good! Here are some comments:

  • could you make sure that the header reader/parser also takes units into account?
  • a unit test verifying the header formating then parsing would be nice
  • we might want to squeeze this into the upcoming 2.1 RC7 release
  • could you sign a JCA (unless already done) so we can pull this contribution?

Thanks for the contribution :)


Thank you very much for the comments. Sadly, I don't have a lot of time these days. I'll see what I can do but I guess it takes at least two weeks till I find time to finish the pull request. Sorry :(

@thboileau thboileau was assigned

No problem for the delay. The highest priority is the signed JCA as we can try to handle to rest ourselves later on if necessary


Looking how simple the fix is, we'll just reimplement it ourselves so you don't have to provide a JCA.

@thboileau thboileau referenced this pull request from a commit
Thierry Boileau Added custom Content-Range units to the Range-Class (issue #618)). Re…
…ported by rmetzger.

Thanks for reporting this, I've updated the 2.2m1.
I agree that this does not concern the reading of ranges from the HTTP request. HTTP 1.1 servers are not required to support such ranges.

@thboileau thboileau closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 11, 2012
  1. @rmetzger
This page is out of date. Refresh to see the latest.
24 modules/org.restlet/src/org/restlet/data/
@@ -68,6 +68,12 @@
* available from the index, then use the {@value #SIZE_MAX} constant.
private volatile long size;
+ /**
+ * Specifies the unit of the range. The HTTP/1.1 protocol specifies
+ * only 'bytes', but other ranges are allowed {@link}
+ */
+ private volatile String unitName = "bytes";
* Default constructor defining a range starting on the first byte and with
@@ -187,4 +193,22 @@ public void setIndex(long index) {
public void setSize(long size) {
this.size = size;
+ /**
+ * Returns the name of the range unit name.
+ * @return
+ * The name of the range
+ */
+ public String getUnitName() {
+ return unitName;
+ }
+ /**
+ * Setter to define the unit name.
+ * @param unitName
+ * with the name of the unit.
+ */
+ public void setUnitName(String unitName) {
+ this.unitName = unitName;
+ }
4 modules/org.restlet/src/org/restlet/engine/header/
@@ -66,7 +66,9 @@ public static String write(List<Range> ranges) {
* @return {@code range} formatted
public static String write(Range range, long size) {
- StringBuilder b = new StringBuilder("bytes ");
+ StringBuilder b = new StringBuilder();
+ b.append(range.getUnitName());
+ b.append(' ');
if (range.getIndex() >= Range.INDEX_FIRST) {
Something went wrong with that request. Please try again.