Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phantom #29

Merged
merged 3 commits into from
Dec 30, 2016
Merged

phantom #29

merged 3 commits into from
Dec 30, 2016

Conversation

jimmy-zha
Copy link
Contributor

修改phantom下载器丢失cookie的问题

@andeya
Copy link
Owner

andeya commented Dec 30, 2016

是否做过了测试?

@jimmy-zha
Copy link
Contributor Author

做过了多次测试的。

@jimmy-zha
Copy link
Contributor Author

Set-Cookie 里应该放的是一个数组,读取的时候数据的每一个元素会被实例成一个cookie。存放的时候把整个cookie当成一个字符串存进去的。所以只取到按";"分割的第一条cookie

func readSetCookies(h Header) []*Cookie {
cookieCount := len(h["Set-Cookie"])
if cookieCount == 0 {
return []*Cookie{}
}
cookies := make([]*Cookie, 0, cookieCount)
for _, line := range h["Set-Cookie"] {
parts := strings.Split(strings.TrimSpace(line), ";")
if len(parts) == 1 && parts[0] == "" {
continue
}
parts[0] = strings.TrimSpace(parts[0])
j := strings.Index(parts[0], "=")
if j < 0 {
continue
}
name, value := parts[0][:j], parts[0][j+1:]
if !isCookieNameValid(name) {
continue
}
value, ok := parseCookieValue(value, true)
if !ok {
continue
}
c := &Cookie{
Name: name,
Value: value,
Raw: line,
}

@jimmy-zha jimmy-zha closed this Dec 30, 2016
@andeya andeya reopened this Dec 30, 2016
@andeya andeya merged commit 273029d into andeya:master Dec 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants