06-content-negotiation, "content-type" required when encoding is "gzip"
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 442
- Forks
- 104
- PR merge metrics
- No merged PRs in 30d
Description
When accept-encoding is gzip, we need to set the content-type to text/plain.
this.response.set('Content-Encoding', 'gzip');
this.response.body = yield gzip('hello world');
The above code would fail the test because, when content-enconding is gzip, the default content-type is application/octet-stream.
Adding the content-type assignment would solve the problem.
this.response.set('Content-Encoding', 'gzip');
this.response.set('content-type', 'text/plain');
this.response.body = yield gzip('hello world');
It takes me a lot time to understand what this chapter is focusing on.
Here is one solution in case anyone need.
app.use(function* () {
const ae = this.request.acceptsEncodings('gzip', 'identity');
switch (ae) {
case 'gzip':
this.response.set('Content-Encoding', 'gzip');
this.response.set('content-type', 'text/plain');
this.response.body = yield gzip('hello world');
break;
case 'identity':
this.response.set('Content-Encoding', 'identity');
this.response.body = 'hello world';
break;
default:
break;
}
});
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the chapter 06 content-negotiation example and the test that fails for a gzip response. Verify the response handling shown in the issue, then ensure the gzip case declares text/plain as its content type and the test passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100