Can I replace net/http with "go mod edit -replace"

I’m using go v1.17 and I have to modify net/http to add new feature to http protocol.

I’m on Windows and when I modify directly source code of net/http module in directory where GOROOT is installed
it works, but I need solution which will be easier to follow by user which is installing my go http server.

I copied net/http to my server directory and modified go.mod with

go mod edit -replace (I put 0 instead of o because forum formats it as page link)

but after launch it still uses original net/http module.

When I named copied module with different name (http instead of net/http) and modified go.mod to point to modified package folder it obviously worked, but this solution has downside of changing every “import net/http” to “import http” in modified net/http module and modules which use net/http in the project.

My question is: Am I doing something wrong ? Is it even possible to modify path to go internal module ? Is it possible to achieve what I’m trying with different solution to make installation of my program simpler.

You can use go mod vendor command, which will create a folder where all packages you use will be stored. Then, simply update packages you want there and build it with -mod=vendor flag

But tbh if your additions to the standard library could be used outside, I will advise to just write your own package as a wrapper with upgrades you need and use it.

I did as you wrote before your reply, but I did not know about “go mod vendor” command and I did everything manually (downloaded every dependency module and changed path with go mod edit -replace). I think that it is not possible to did this without modifying source code of dependency modules, so I’m accepting your answer as solution.