An open API service indexing awesome lists of open source software.

https://github.com/heruan/jaxrs-range-filter

HTTP Ranged Requests for JAX-RS.
https://github.com/heruan/jaxrs-range-filter

java jax-rs serve-byte-ranges

Last synced: about 1 year ago
JSON representation

HTTP Ranged Requests for JAX-RS.

Awesome Lists containing this project

README

          

= HTTP Ranged Requests for JAX-RS

image:https://img.shields.io/github/release/heruan/jaxrs-range-filter.svg[link=https://github.com/heruan/jaxrs-range-filter/releases,title=Latest release]
image:https://img.shields.io/maven-central/v/to.lova.jaxrs/jaxrs-range-filter.svg[title=jaxrs-range-filter]
image:https://img.shields.io/github/downloads/heruan/jaxrs-range-filter/total.svg[link=https://github.com/heruan/jaxrs-range-filter/archive/master.zip,title=GitHub]
image:https://img.shields.io/circleci/project/github/heruan/jaxrs-range-filter.svg[link=https://circleci.com/gh/heruan/jaxrs-range-filter,title=CricleCI]
image:https://img.shields.io/codecov/c/github/heruan/jaxrs-range-filter.svg[link=https://codecov.io/gh/heruan/jaxrs-range-filter,title=Codecov]
image:https://img.shields.io/github/license/heruan/jaxrs-range-filter.svg[link=http://www.apache.org/licenses/LICENSE-2.0.html,title=Apache License 2.0]

## Example usage

[source,xml]
----

to.lova.jaxrs
jaxrs-range-filter
1.0.0

----

[source,java]
----
import java.util.Collections;
import java.util.Set;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("app")
public class MyApplication extends Application {

@Override
public Set> getClasses() {
return Collections.singleton(RangeResponseFilter.class);
}

}
----

[source,java]
----
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("alphabet")
public class AlphabetResource {

@GET
@Produces(MediaType.TEXT_PLAIN)
public String alphabet() {
return "abcdefghijklmnopqrstuvwxyz";
}

}
----

Then JAX-RS will serve byte ranges whenever a HTTP `Range` header is present on
the request, e.g.

[source]
----
$ curl -i http://localhost:8080/app/alphabet
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 26

abcdefghijklmnopqrstuvwxyz
----

[source]
----
$ curl -i http://localhost:8080/app/alphabet -H "Range: bytes=6-10"
HTTP/1.1 206 Partial Content
Accept-Ranges: bytes
Content-Range: bytes 6-10/26
Content-Type: text/plain
Content-Length: 5

ghijk
----

[source]
----
$ curl -i http://localhost:8080/app/alphabet -H "Range: bytes=6-10,18-"
HTTP/1.1 206 Partial Content
Accept-Ranges: bytes
Content-Type: multipart/byteranges; boundary=VXTwimfDqIB3LRZ2jjQ8vxbSvnGAB2sMn3UVq
Content-Length: 257

--VXTwimfDqIB3LRZ2jjQ8vxbSvnGAB2sMn3UVq
Content-Type: text/plain
Content-Range: bytes 6-10/26

ghijk
--VXTwimfDqIB3LRZ2jjQ8vxbSvnGAB2sMn3UVq
Content-Type: text/plain
Content-Range: bytes 18-26/26

stuvwxyz
--VXTwimfDqIB3LRZ2jjQ8vxbSvnGAB2sMn3UVq--
----