Skip to content
This repository

Add custom Content-Range unit names. #618

Closed
wants to merge 1 commit into from

3 participants

Robert Metzger Jerome Louvel Thierry Boileau
Robert Metzger

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: http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.12

The documentation of Dojo says: http://dojotoolkit.org/reference-guide/1.7/dojox/data/JsonRestStore.html

"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"

Jerome Louvel
Owner

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? http://www.restlet.org/community/contribute

Thanks for the contribution :)

Robert Metzger

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

Jerome Louvel
Owner

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

Jerome Louvel
Owner

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

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

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.

Thierry Boileau thboileau closed this December 21, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jul 11, 2012
Robert Metzger Added custom Content-Range units to the Range-Class. 180ee45
This page is out of date. Refresh to see the latest.
24  modules/org.restlet/src/org/restlet/data/Range.java
@@ -68,6 +68,12 @@
68 68
      * available from the index, then use the {@value #SIZE_MAX} constant.
69 69
      */
70 70
     private volatile long size;
  71
+    
  72
+    /**
  73
+     * Specifies the unit of the range. The HTTP/1.1 protocol specifies
  74
+     * only 'bytes', but other ranges are allowed {@link http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.12}
  75
+     */
  76
+    private volatile String unitName = "bytes";
71 77
 
72 78
     /**
73 79
      * Default constructor defining a range starting on the first byte and with
@@ -187,4 +193,22 @@ public void setIndex(long index) {
187 193
     public void setSize(long size) {
188 194
         this.size = size;
189 195
     }
  196
+
  197
+    /**
  198
+     * Returns the name of the range unit name.
  199
+     * @return 
  200
+     * 			The name of the range
  201
+     */
  202
+	public String getUnitName() {
  203
+		return unitName;
  204
+	}
  205
+	
  206
+	/**
  207
+	 * Setter to define the unit name.
  208
+	 * @param unitName 
  209
+	 * 			with the name of the unit.
  210
+	 */
  211
+	public void setUnitName(String unitName) {
  212
+		this.unitName = unitName;
  213
+	}
190 214
 }
4  modules/org.restlet/src/org/restlet/engine/header/RangeWriter.java
@@ -66,7 +66,9 @@ public static String write(List<Range> ranges) {
66 66
      * @return {@code range} formatted
67 67
      */
68 68
     public static String write(Range range, long size) {
69  
-        StringBuilder b = new StringBuilder("bytes ");
  69
+        StringBuilder b = new StringBuilder();
  70
+        b.append(range.getUnitName());
  71
+        b.append(' ');
70 72
 
71 73
         if (range.getIndex() >= Range.INDEX_FIRST) {
72 74
             b.append(range.getIndex());
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.