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

go语言中url组装缺少端口号问题 #320

Open
shawdongGithub opened this issue Aug 30, 2022 · 1 comment
Open

go语言中url组装缺少端口号问题 #320

shawdongGithub opened this issue Aug 30, 2022 · 1 comment

Comments

@shawdongGithub
Copy link

url组装缺少port

在tea.go中 307所在行位置

requestURL := ""
request.Domain = request.Headers["host"]
requestURL = fmt.Sprintf("%s://%s%s", StringValue(request.Protocol), StringValue(request.Domain),StringValue(request.Pathname))

URL一般情况由 protocol + host + port + pathname组成,很明显以上代码缺少port端口号

@shawdongGithub
Copy link
Author

shawdongGithub commented Oct 12, 2022

在python中 Tea/core.py中 第61-78行

        host = request.headers.get('host')
        if not host:
            raise RequiredArgumentException('endpoint')
        else:
            host = host.rstrip('/')
        protocol = f'{request.protocol.lower()}://'
        pathname = request.pathname

        if host.startswith(('http://', 'https://')):
            protocol = ''

        if request.port == 80:
            port = ''
        else:
            port = f':{request.port}'

        url = protocol + host + port + pathname

但是在tea.go中 207-309 行

	if request.Method == nil {
		request.Method = String("GET")
	}

	if request.Protocol == nil {
		request.Protocol = String("http")
	} else {
		request.Protocol = String(strings.ToLower(StringValue(request.Protocol)))
	}

	requestURL := ""
	request.Domain = request.Headers["host"]
	requestURL = fmt.Sprintf("%s://%s%s", StringValue(request.Protocol), StringValue(request.Domain), StringValue(request.Pathname))

很明显go中缺少对url的组装中缺少port端口号

修复建议

	requestURL := ""
	request.Domain = request.Headers["host"]
	if request.Port == nil{
		requestURL = fmt.Sprintf("%s://%s%s", StringValue(request.Protocol), StringValue(request.Domain), StringValue(request.Pathname))
	}else {
		requestURL = fmt.Sprintf("%s://%s:%d%s", StringValue(request.Protocol), StringValue(request.Domain),IntValue(request.Port), StringValue(request.Pathname))
	}

**请尽快修复,谢谢🙏🙏 @JacksonTian @denverdino @peze @jasonHzq **

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

No branches or pull requests

1 participant