Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
feat(crawler): optimize set cookie parse logic
Browse files Browse the repository at this point in the history
  • Loading branch information
beetcb committed Mar 8, 2021
1 parent 6b8e16c commit 5cd7cdc
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions crawler/casLogIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,19 @@ module.exports = async (school, user) => {
/**
* refresh cookie in headers (for next request)
*
* @param {Object} headers refresh target
* @param {Object} res response object
* @param {Object} cookie
* @param {object} headers refresh target
* @param {object} res response object
* @return {boolean} true if set-cookie exists
*/
function reCook(res, isCas) {
let cook
try {
cook = res.headers.raw()['set-cookie']
cook.forEach(e => {
const setCookieList = res.headers.raw()['set-cookie']
setCookieList.forEach(e => {
const content = e.split(';').shift()
if (e.includes('authserver')) {
cookie.swms += e.match(/^(\w|\d|\s)+\=(\w|\d|\s|\-)+;/)[0]
cookie.swms += `${content}; `
} else {
cookie.campusphere += e.match(/^(\w|\d|\s)+\=(\w|\d|\s|\-)+;/)[0]
cookie.campusphere += `${content}; `
}
})
} catch (e) {
Expand Down

0 comments on commit 5cd7cdc

Please sign in to comment.