Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Manipulate the HTTP Vary header

License

NotificationsYou must be signed in to change notification settings

jshttp/vary

Repository files navigation

NPM VersionNPM DownloadsNode.js VersionBuild StatusCoverage Status

Manipulate the HTTP Vary header

Installation

This is aNode.js module available through thenpm registry. Installation is done using thenpm install command:

$ npm install vary

API

varvary=require('vary')

vary(res, field)

Adds the given headerfield to theVary response header ofres.This can be a string of a single field, a string of a validVaryheader, or an array of multiple fields.

This will append the header if not already listed, otherwise leavesit listed in the current location.

// Append "Origin" to the Vary header of the responsevary(res,'Origin')

vary.append(header, field)

Adds the given headerfield to theVary response header stringheader.This can be a string of a single field, a string of a validVary header,or an array of multiple fields.

This will append the header if not already listed, otherwise leavesit listed in the current location. The new header string is returned.

// Get header string appending "Origin" to "Accept, User-Agent"vary.append('Accept, User-Agent','Origin')

Examples

Updating the Vary header when content is based on it

varhttp=require('http')varvary=require('vary')http.createServer(functiononRequest(req,res){// about to user-agent sniffvary(res,'User-Agent')varua=req.headers['user-agent']||''varisMobile=/mobi|android|touch|mini/i.test(ua)// serve site, depending on isMobileres.setHeader('Content-Type','text/html')res.end('You are (probably) '+(isMobile ?'' :'not ')+'a mobile user')})

Testing

$ npmtest

License

MIT


[8]ページ先頭

©2009-2025 Movatter.jp