\href{https://npmjs.org/package/vary}{\texttt{ }} \href{https://npmjs.org/package/vary}{\texttt{ }} \href{https://nodejs.org/en/download}{\texttt{ }} \href{https://travis-ci.org/jshttp/vary}{\texttt{ }} \href{https://coveralls.io/r/jshttp/vary}{\texttt{ }}

Manipulate the HTTP Vary header\hypertarget{md_sfcode_node_modules_vary_README_autotoc_md31766}{}\doxysection{Installation}\label{md_sfcode_node_modules_vary_README_autotoc_md31766}
This is a \href{https://nodejs.org/en/}{\texttt{ Node.\+js}} module available through the \href{https://www.npmjs.com/}{\texttt{ npm registry}}. Installation is done using the \href{https://docs.npmjs.com/getting-started/installing-npm-packages-locally}{\texttt{ {\ttfamily npm install} command}}\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm install vary }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_vary_README_autotoc_md31767}{}\doxysection{API}\label{md_sfcode_node_modules_vary_README_autotoc_md31767}

\begin{DoxyCode}{0}
\DoxyCodeLine{var vary = require('vary') }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_vary_README_autotoc_md31768}{}\doxysubsection{vary(res, field)}\label{md_sfcode_node_modules_vary_README_autotoc_md31768}
Adds the given header {\ttfamily field} to the {\ttfamily Vary} response header of {\ttfamily res}. This can be a string of a single field, a string of a valid {\ttfamily Vary} header, or an array of multiple fields.

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


\begin{DoxyCode}{0}
\DoxyCodeLine{// Append "{}Origin"{} to the Vary header of the response}
\DoxyCodeLine{vary(res, 'Origin') }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_vary_README_autotoc_md31769}{}\doxysubsection{vary.\+append(header, field)}\label{md_sfcode_node_modules_vary_README_autotoc_md31769}
Adds the given header {\ttfamily field} to the {\ttfamily Vary} response header string {\ttfamily header}. This can be a string of a single field, a string of a valid {\ttfamily Vary} header, or an array of multiple fields.

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


\begin{DoxyCode}{0}
\DoxyCodeLine{// Get header string appending "{}Origin"{} to "{}Accept, User-\/Agent"{}}
\DoxyCodeLine{vary.append('Accept, User-\/Agent', 'Origin') }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_vary_README_autotoc_md31770}{}\doxysection{Examples}\label{md_sfcode_node_modules_vary_README_autotoc_md31770}
\hypertarget{md_sfcode_node_modules_vary_README_autotoc_md31771}{}\doxysubsection{Updating the Vary header when content is based on it}\label{md_sfcode_node_modules_vary_README_autotoc_md31771}

\begin{DoxyCode}{0}
\DoxyCodeLine{var http = require('http')}
\DoxyCodeLine{var vary = require('vary')}
\DoxyCodeLine{}
\DoxyCodeLine{http.createServer(function onRequest (req, res) \{}
\DoxyCodeLine{  // about to user-\/agent sniff}
\DoxyCodeLine{  vary(res, 'User-\/Agent')}
\DoxyCodeLine{}
\DoxyCodeLine{  var ua = req.headers['user-\/agent'] || ''}
\DoxyCodeLine{  var isMobile = /mobi|android|touch|mini/i.test(ua)}
\DoxyCodeLine{}
\DoxyCodeLine{  // serve site, depending on isMobile}
\DoxyCodeLine{  res.setHeader('Content-\/Type', 'text/html')}
\DoxyCodeLine{  res.end('You are (probably) ' + (isMobile ? '' : 'not ') + 'a mobile user')}
\DoxyCodeLine{\}) }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_vary_README_autotoc_md31772}{}\doxysection{Testing}\label{md_sfcode_node_modules_vary_README_autotoc_md31772}

\begin{DoxyCode}{0}
\DoxyCodeLine{\$ npm test }

\end{DoxyCode}
\hypertarget{md_sfcode_node_modules_vary_README_autotoc_md31773}{}\doxysection{License}\label{md_sfcode_node_modules_vary_README_autotoc_md31773}
\mbox{[}MIT\mbox{]}(LICENSE) 