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

Bug: invalid memory address or nil pointer dereference #330

Closed
zbqBaoqing opened this issue Apr 21, 2020 · 1 comment · Fixed by #340
Closed

Bug: invalid memory address or nil pointer dereference #330

zbqBaoqing opened this issue Apr 21, 2020 · 1 comment · Fixed by #340
Assignees
Labels
bug v2 For resty v2

Comments

@zbqBaoqing
Copy link

for resty@v2.2.0;
when i set debug is true, and new a client with NewWhiteClient(http.DefaultClient),
the client Jar is nil . in requestLogger func used composeHeaders

func requestLogger(c *Client, r *Request) error {

fmt.Sprintf("HEADERS:\n%s\n", composeHeaders(c, r, rl.Header)) +

func composeHeaders(c *Client, r *Request, hdrs http.Header) string {
	str := make([]string, 0, len(hdrs))
	for _, k := range sortHeaderKeys(hdrs) {
		var v string
		if k == "Cookie" {
			cv := strings.TrimSpace(strings.Join(hdrs[k], ", "))
                       // Bug: c.GetClient().Jar maybe is nil
			for _, c := range c.GetClient().Jar.Cookies(r.RawRequest.URL) {  
				if cv != "" {
					cv = cv + "; " + c.String()
				} else {
					cv = c.String()
				}
			}
			v = strings.TrimSpace(fmt.Sprintf("%25s: %s", k, cv))
		} else {
			v = strings.TrimSpace(fmt.Sprintf("%25s: %s", k, strings.Join(hdrs[k], ", ")))
		}
		if v != "" {
			str = append(str, "\t"+v)
		}
	}
	return strings.Join(str, "\n")
}
@jeevatkm
Copy link
Member

@zbqyexingkong Thanks for reporting an issue. Sure I will address the nil pointer issue with adding nill check.

@jeevatkm jeevatkm self-assigned this May 11, 2020
@jeevatkm jeevatkm added the bug label May 11, 2020
@jeevatkm jeevatkm added this to the v2.3.0 Milestone milestone May 11, 2020
jeevatkm added a commit that referenced this issue May 11, 2020
@jeevatkm jeevatkm added the v2 For resty v2 label May 11, 2020
jeevatkm added a commit that referenced this issue May 11, 2020
@jeevatkm jeevatkm mentioned this issue May 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug v2 For resty v2
Development

Successfully merging a pull request may close this issue.

2 participants