There are projects that do this already e.g. https://github.com/lwthiker/curl-impersonate