Map type of resource to appropriate MIME type and use it to set Content-Type header in HTTP response
时间: 2023-12-06 07:39:36 浏览: 100
Here are some commonly used resource types and their corresponding MIME types:
- Text files: text/plain
- HTML files: text/html
- CSS files: text/css
- JavaScript files: application/javascript
- JSON files: application/json
- XML files: application/xml
- Images (JPEG, PNG, etc.): image/jpeg, image/png, etc.
- Audio files (MP3, WAV, etc.): audio/mpeg, audio/wav, etc.
- Video files (MP4, AVI, etc.): video/mp4, video/avi, etc.
To set the Content-Type header in an HTTP response, you can use the setHeader() method of the response object in your server-side code. For example, if you want to set the Content-Type to "text/html" for an HTML file, you can do the following in Node.js:
```
response.setHeader('Content-Type', 'text/html');
```
Or if you are using Express.js, you can use the following:
```
response.type('html');
```
阅读全文