Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

will you Consider changing the cookie module.because cookie-jar has some bug. #672

Closed
wants to merge 3 commits into from

3 participants

@sxyizhiren

will you Consider changing the cookie module.because cookie-jar has some bug.
such as #670
such as #669

so I change the cookie-jar,instead of using tough-cookie.

sxyizhiren added some commits
@sxyizhiren sxyizhiren change the cookie module
change the cookie module ,更改不够完善的cookie模块,改成tough-cookie
7c20348
@sxyizhiren sxyizhiren 去掉注释,去掉分号(使代码风格一致)
去掉注释,去掉分号(使代码风格一致)
ff181d6
@sxyizhiren sxyizhiren readme回退,怕pull request干扰文件比较结果
readme回退,怕pull request干扰文件比较结果
c82f605
@mikeal
Owner

i'm really excited about this change.

can you change the module name back to request, and translate the comment in to english :)

@LoicMahieu LoicMahieu closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 28, 2013
  1. @sxyizhiren

    change the cookie module

    sxyizhiren authored
    change the cookie module ,更改不够完善的cookie模块,改成tough-cookie
Commits on Sep 29, 2013
  1. @sxyizhiren

    去掉注释,去掉分号(使代码风格一致)

    sxyizhiren authored
    去掉注释,去掉分号(使代码风格一致)
Commits on Sep 30, 2013
  1. @sxyizhiren

    readme回退,怕pull request干扰文件比较结果

    sxyizhiren authored
    readme回退,怕pull request干扰文件比较结果
This page is out of date. Refresh to see the latest.
Showing with 49 additions and 34 deletions.
  1. +2 −2 index.js
  2. +6 −6 package.json
  3. +41 −26 request.js
View
4 index.js
@@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-var Cookie = require('cookie-jar')
- , CookieJar = Cookie.Jar
+var toughCookie=require('tough-cookie')
+ , CookieJar=toughCookie.CookieJar
, cookieJar = new CookieJar
, copy = require('./lib/copy')
View
12 package.json
@@ -1,5 +1,5 @@
{
- "name": "request",
+ "name": "request-5291",
"description": "Simplified HTTP request client.",
"tags": [
"http",
@@ -7,11 +7,11 @@
"util",
"utility"
],
- "version": "2.27.1",
- "author": "Mikeal Rogers <mikeal.rogers@gmail.com>",
+ "version": "2.27.2",
+ "author": "sxyizhiren <786647787@qq.com>",
"repository": {
"type": "git",
- "url": "http://github.com/mikeal/request.git"
+ "url": "https://github.com/sxyizhiren/request-5291"
},
"bugs": {
"url": "http://github.com/mikeal/request/issues"
@@ -29,10 +29,10 @@
"hawk": "~1.0.0",
"aws-sign": "~0.3.0",
"oauth-sign": "~0.3.0",
- "cookie-jar": "~0.3.0",
"node-uuid": "~1.4.0",
"mime": "~1.2.9",
- "form-data": "~0.1.0"
+ "form-data": "~0.1.0",
+ "tough-cookie": "~0.9.15"
},
"scripts": {
"test": "node tests/run.js"
View
67 request.js
@@ -20,8 +20,8 @@ var http = require('http')
, ForeverAgent = require('forever-agent')
, FormData = require('form-data')
- , Cookie = require('cookie-jar')
- , CookieJar = Cookie.Jar
+ , toughCookie=require('tough-cookie')
+ , CookieJar=toughCookie.CookieJar
, cookieJar = new CookieJar
, copy = require('./lib/copy')
@@ -658,10 +658,15 @@ Request.prototype.onResponse = function (response) {
var addCookie = function (cookie) {
if (self._jar){
- if(self._jar.add){
- self._jar.add(new Cookie(cookie))
+ if(self._jar.setCookie){
+ self._jar.setCookie(cookie, self.uri.href, function(err){
+ if(err)console.log('set cookie err:'+cookie)
+ })
+ }else{
+ cookieJar.setCookie(cookie, self.uri.href, function(err){
+ if(err)console.log('set cookie err:'+cookie)
+ })
}
- else cookieJar.add(new Cookie(cookie))
}
}
@@ -1161,30 +1166,40 @@ Request.prototype.jar = function (jar) {
this.originalCookieHeader = this.getHeader('cookie')
}
- if (!jar) {
- // disable cookies
- cookies = false
- this._disableCookies = true
- } else if (jar && jar.get) {
- // fetch cookie from the user defined cookie jar
- cookies = jar.get({ url: this.uri.href })
- } else {
- // fetch cookie from the global cookie jar
- cookies = cookieJar.get({ url: this.uri.href })
+ if(!jar){
+ cookies = false
+ this._disableCookies = true
+ }else if(jar && jar.getCookieString){
+ var urihref = this.uri.href
+ jar.getCookieString(urihref,function(err,httpCookie){
+ if(err){
+ //err的时候httpCookie为空
+ console.log('get cookieString err:'+urihref)
+ }else{
+ cookies = httpCookie
+ }
+ })
+ }else{
+ var urihref = this.uri.href
+ cookieJar.getCookieString(urihref,function(err,httpCookie){
+ if(err){
+ console.log('get cookieString err:'+urihref)
+ }else{
+ cookies = httpCookie
+ }
+ })
}
- if (cookies && cookies.length) {
- var cookieString = cookies.map(function (c) {
- return c.name + "=" + c.value
- }).join("; ")
-
- if (this.originalCookieHeader) {
- // Don't overwrite existing Cookie header
- this.setHeader('cookie', this.originalCookieHeader + '; ' + cookieString)
- } else {
- this.setHeader('cookie', cookieString)
- }
+ //cookies是个string
+ if(cookies && cookies.length){
+ if (this.originalCookieHeader) {
+ // Don't overwrite existing Cookie header
+ this.setHeader('cookie', this.originalCookieHeader + '; ' + cookies)
+ } else {
+ this.setHeader('cookie', cookies)
+ }
}
+
this._jar = jar
return this
}
Something went wrong with that request. Please try again.