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

chore: stop using go:linkname for http.registerOnHitEOF, http.requestBodyRemains #1275

Merged
merged 2 commits into from
May 18, 2024

Conversation

hunshcn
Copy link

@hunshcn hunshcn commented May 18, 2024

relate to #952 (comment)

@hunshcn
Copy link
Author

hunshcn commented May 18, 2024

按照标准库实现了一下

@wwqgtxx
Copy link
Collaborator

wwqgtxx commented May 18, 2024

@hunshcn 我比较好奇的是可以覆盖原来requestBodyRemains的判断场景么

@hunshcn
Copy link
Author

hunshcn commented May 18, 2024

@hunshcn 我比较好奇的是可以覆盖原来requestBodyRemains的判断场景么

// requestBodyRemains reports whether future calls to Read
// on rc might yield more data.
func requestBodyRemains(rc io.ReadCloser) bool {
	if rc == NoBody {
		return false
	}
	switch v := rc.(type) {
	case *expectContinueReader:
		return requestBodyRemains(v.readCloser)
	case *body:
		return v.bodyRemains()
	default:
		panic("unexpected type " + fmt.Sprintf("%T", rc))
	}
}

由于我们的 request 是 readRequest 读取出来的,通过源码可以得知其实 Body 只有可能是 *body / NoBody

所以这个pr中可以直接if request.Body == nil || request.Body == http.NoBody {
其实这个 if nil 都可以不需要,但是作为防御性编程。

@hunshcn
Copy link
Author

hunshcn commented May 18, 2024

话说 go.mod 不 stable 啊...是不是得 update 一下并且在 ci 加个 verify go mod

@wwqgtxx
Copy link
Collaborator

wwqgtxx commented May 18, 2024

话说 go.mod 不 stable 啊...是不是得 update 一下并且在 ci 加个 verify go mod

我自己提交的时候都是go mod tidy再提交的,应该没有问题

@hunshcn
Copy link
Author

hunshcn commented May 18, 2024

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   test/go.mod
	modified:   test/go.sum

test/go.mod 不 stable @wwqgtxx

我提个 pr 改造一下 go work 吧

@wwqgtxx
Copy link
Collaborator

wwqgtxx commented May 18, 2024

test应该是很久没管过了,每次也没有同步更新它的习惯,或者说从clash分支出来之后就从没用过test模块
个人觉得并不太需要管这个submodule

@wwqgtxx wwqgtxx changed the title feat: stop using go:linkname for http.registerOnHitEOF, http.requestBodyRemains chore: stop using go:linkname for http.registerOnHitEOF, http.requestBodyRemains May 18, 2024
@wwqgtxx wwqgtxx merged commit 00e361c into MetaCubeX:Alpha May 18, 2024
49 checks passed
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.

None yet

2 participants