subzerocloud / subzero-starter-kit

Starter Kit and tooling for authoring GraphQL/REST API backends with subZero

Home Page:https://subzero.cloud

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is Range ignored with subzero?

octaltree opened this issue · comments

GET /people HTTP/1.1
Range-Unit: items
Range: 0-19

PostgREST document teaches me this.
Is Range ignored with subzero?

$ git clone https://github.com/subzerocloud/subzero-starter-kit test
$ cd test
$ docker-compose up -d
$ curl --verbose --http1.1 'http://localhost:8080/rest/todos?select=id' # This does expected

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying ::1:8080...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET /rest/todos?select=id HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.66.0
> Accept: */*
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: openresty
< Date: Tue, 29 Oct 2019 09:49:17 GMT
< Content-Type: application/json; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Vary: Accept-Encoding
< Content-Range: 0-2/*
< X-Frame-Options: SAMEORIGIN
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Content-Location: /rest/todos?select=id
< Request-Time: 0.020
< Method: GET
< Cache-Engine: "nginx"
< Cache-Status: BYPASS
< Cache-Key: 56002b0d5a4e057c37780181f18d7f4c
< Cache-TTL: 60
< 
{ [72 bytes data]

100    61    0    61    0     0   2772      0 --:--:-- --:--:-- --:--:--  2772
* Connection #0 to host localhost left intact
[{"id":"dG9kbzox"}, 
 {"id":"dG9kbzoz"}, 
 {"id":"dG9kbzo2"}]

$ curl --verbose --http1.1 'http://localhost:8080/rest/todos?select=id' -H 'Content-Range: items' -H 'Range: 0-1' # This fetched more items than range.

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0*   Trying ::1:8080...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> GET /rest/todos?select=id HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.66.0
> Accept: */*
> Range-Unit: items
> Range: 0-1
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Server: openresty
< Date: Tue, 29 Oct 2019 10:07:35 GMT
< Content-Type: application/json; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
< Vary: Accept-Encoding
< Content-Range: 0-2/*
< X-Frame-Options: SAMEORIGIN
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Content-Location: /rest/todos?select=id
< Request-Time: 0.003
< Method: GET
< Cache-Engine: "nginx"
< Cache-Status: BYPASS
< Cache-Key: 0951892c2e83a4ef06701453128df4e0
< Cache-TTL: 60
< 
{ [72 bytes data]

100    61    0    61    0     0  20333      0 --:--:-- --:--:-- --:--:-- 20333
* Connection #0 to host localhost left intact
[{"id":"dG9kbzox"}, 
 {"id":"dG9kbzoz"}, 
 {"id":"dG9kbzo2"}]

I can confirm this is indeed the case but the issue is not related to subzero but instead it comes from the fact that nginx is not passing those headers to postgrest and the reason is because the headers (as used but postgrest are invalid). See this discussion PostgREST/postgrest#1089

Instread of range headers, you can achieve the same result (and in a easier fassion) by using limit/offset parameters
/people?limit=15&offset=30
Those parameters also have the advantage that they can be specified for the embedded resources