Skip to content

Commit

Permalink
support http2
Browse files Browse the repository at this point in the history
  • Loading branch information
sogaani committed Jul 28, 2018
1 parent 12ee5ab commit 831e9cb
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ var deprecate = require('depd')('cookies')
var Keygrip = require('keygrip')
var http = require('http')
var cache = {}
var http2 = null;
try{
http2 = require('http2');
}catch(_){
}

/**
* RegExp to match field-content in RFC 7230 sec 3.2
Expand Down Expand Up @@ -111,7 +116,9 @@ Cookies.prototype.set = function(name, value, opts) {
headers = pushCookie(headers, cookie)
}

var setHeader = res.set ? http.OutgoingMessage.prototype.setHeader : res.setHeader
var protoSetHeader = http2 && res instanceof http2.Http2ServerResponse ?
http2.Http2ServerResponse.prototype.setHeader : http.OutgoingMessage.prototype.setHeader;
var setHeader = res.set ? protoSetHeader : res.setHeader
setHeader.call(res, 'Set-Cookie', headers)
return this
};
Expand Down

0 comments on commit 831e9cb

Please sign in to comment.