Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(response interceptor): align with nodejs default utf8 #567

Merged
merged 2 commits into from
Apr 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ const proxy = createProxyMiddleware({
* Intercept response and replace 'Hello' with 'Goodbye'
**/
onProxyRes: responseInterceptor(async (responseBuffer, proxyRes, req, res) => {
const response = responseBuffer.toString('utf-8'); // convert buffer to string
const response = responseBuffer.toString('utf8'); // convert buffer to string
return response.replace('Hello', 'Goodbye'); // manipulate response and return the result
}),
});
Expand Down
2 changes: 1 addition & 1 deletion examples/response-interceptor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const jsonPlaceholderProxy = createProxyMiddleware({
console.log(exchange);

// log original response
// console.log(`[DEBUG] original response:\n${buffer.toString('utf-8')}`);
// console.log(`[DEBUG] original response:\n${buffer.toString('utf8')}`);

// set response content-type
res.setHeader('content-type', 'application/json; charset=utf-8');
Expand Down
6 changes: 3 additions & 3 deletions recipes/response-interceptor.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const proxy = createProxyMiddleware({
onProxyRes: responseInterceptor(async (responseBuffer, proxyRes, req, res) => {
res.statusCode = 418; // set different response status code

const response = responseBuffer.toString('utf-8');
const response = responseBuffer.toString('utf8');
return response.replace('Hello', 'Teapot');
}),
});
Expand All @@ -45,7 +45,7 @@ const proxy = createProxyMiddleware({
console.log(exchange); // [DEBUG] GET / -> http://www.example.com [200]

// log complete response
const response = responseBuffer.toString('utf-8');
const response = responseBuffer.toString('utf8');
console.log(response); // log response body

return responseBuffer;
Expand All @@ -65,7 +65,7 @@ const proxy = createProxyMiddleware({
onProxyRes: responseInterceptor(async (responseBuffer, proxyRes, req, res) => {
// detect json responses
if (proxyRes.headers['content-type'] === 'application/json') {
let data = JSON.parse(responseBuffer.toString('utf-8'));
let data = JSON.parse(responseBuffer.toString('utf8'));

// manipulate JSON data here
data = Object.assign({}, data, { extra: 'foo bar' });
Expand Down