Why is the font different for res.end and res.send?

大憨熊 提交于 2020-01-23 06:36:41

问题


I have the following minimal basic express node js application:

var express = require ('express');
var app = express ();

app.get ('/', function (req, res) {
    res.send ('Hello');
});

app.listen (3000);

When I access this site on localhost:3000 I get a response that looks like:

If I change res.send ('Hello'); to res.end ('Hello');, the response is a different font like:

I am curious; why the difference?


回答1:


If you pass a string to res.send(), it automatically assumes a Content-Type of html.

res.end(), however, simply calls node's underlying end() implementation on the response stream, so no assumptions are made for the Content-Type.

The reason it renders differently is simply a browser decision to render a "pretty" default font for HTML, and a less-styled font for unknown content types.



来源:https://stackoverflow.com/questions/22774811/why-is-the-font-different-for-res-end-and-res-send

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!