fknop/hapi-pagination

Response status code 206 when using metadata in header

peveuve opened this issue · 6 comments

When we use the configuration location='header', the plugin adds the Content-Range header in the response. In this situation, the HTTP protocol demands the response to use the status code 206 (partial content).
The plugin doesn't change the status code, so if the application doesn't set the code itself and the response goes through a CDN like Akamaï, the Content-Range header is removed without notice.

Do you think the plugin should set the status code 206 when using the config location='header' ?
The only drawback is that because the plugin changes the response in a preResponse handler, the application developer won't be able to change it in his code.

If you agree with this, I will send a Pull request.
Otherwise developers will have to manage the response status code themselves.

fknop commented

We should probably allow the developer to change this via a configuration option. Something like:
headerStatusCode or successHeaderStatusCode.

Ok, so it would be something like that :

  meta: {
    location: 'header',
    successStatusCode: 206,
    ...
  }

Actually, we could use it in both situations (metadata in header or body).
206 warns the client the data returned are part of a bigger content, so it can be useful whatever location is set.

fknop commented

Yes, that's true.

Ok, I will send my pull request tomorrow then, thanks.

Pull request is ready for review.

fknop commented

Reviewed.