{"id":16608048,"url":"https://github.com/o8x/native-httpclient","last_synced_at":"2026-04-24T09:32:36.864Z","repository":{"id":57548115,"uuid":"303939298","full_name":"o8x/native-httpclient","owner":"o8x","description":"通过 tcp 和 unix sock 文件发送原生HTTP请求的HTTP客户端","archived":false,"fork":false,"pushed_at":"2020-10-16T09:24:55.000Z","size":20,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-12T02:45:01.256Z","etag":null,"topics":["curl","go","http","http-client","native-http-client","unix-socket"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/o8x.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-14T07:40:30.000Z","updated_at":"2020-10-29T08:33:52.000Z","dependencies_parsed_at":"2022-09-26T18:41:07.319Z","dependency_job_id":null,"html_url":"https://github.com/o8x/native-httpclient","commit_stats":null,"previous_names":["alex-techs/native-httpclient"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/o8x/native-httpclient","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o8x%2Fnative-httpclient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o8x%2Fnative-httpclient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o8x%2Fnative-httpclient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o8x%2Fnative-httpclient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/o8x","download_url":"https://codeload.github.com/o8x/native-httpclient/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/o8x%2Fnative-httpclient/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32216917,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T08:24:32.376Z","status":"ssl_error","status_checked_at":"2026-04-24T08:24:26.731Z","response_time":64,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["curl","go","http","http-client","native-http-client","unix-socket"],"created_at":"2024-10-12T01:24:56.399Z","updated_at":"2026-04-24T09:32:36.849Z","avatar_url":"https://github.com/o8x.png","language":"Go","readme":"NATIVE-HTTP-CLIENT\n======\n\n通过 tcp 和 unix sock 文件发送原生HTTP请求的HTTP客户端\n\n### 开发计划\n- [x] HTTP\n- [x] 302\n- [ ] 公开 test api\n- [ ] HTTPS\n- [ ] TLS\n- [ ] HTTP2\n\n### 获取实例\n\n连接到 TCP\n\n```golang\nclient := NewTcp(\"domain\")\n```\n\n连接到 Socket 文件\n```golang\nclient := NewUnixSock(\"/var/run/docker.sock\")\n```\n\n### 请求 \n\nGET、DELETE、HEAD、OPTIONS\n\n第二个参数将会被处理成 QueryString，追加到url后面。例如：/containers/json?sort=id\n\n```golang\nresponse, err := client.Get(\"/containers/json\", map[string]string{\n     \"sort\": \"id\",\n })\nresponse, err := client.Delete(\"/containers/json\", nil)\nresponse, err := client.Head(\"/containers/json\", nil)\nresponse, err := client.Options(\"/containers/json\", nil)\n```\n\nPOST、PUT、PATCH\n\n同时接受字符串和其它参数类型(将会被格式化为json)\n\n```golang\nresponse, err := client.Post(\"/containers/create\", map[string]string{\n    \"Image\": \"nginx\",\n})\nresponse, err := client.Put(\"/containers/create\", `{\"Image\":\"nginx\"}`)\nresponse, err :=  client.Patch(\"/containers/create\", `{\"Image\":\"nginx\"}`)\n```\n\n### 原始 HTTP 协议\n\n调用请求API，将会生成类似如下两种的原始 HTTP 协议进行发送，其中的GET和POST将会被替换成实际协议。\n\n\nGET、DELETE、HEAD、OPTIONS\n\n```ini\nGET /containers/json HTTP/1.1\nHost: domain:80\nConnection: close\n```\n\nPOST、PUT、PATCH\n```ini \nPOST /containers/create?name=nginx HTTP/1.1\nHost: localhost\nConnection: close\nContent-Length: 17\nAccept: */*\nContent-Type: application/json;charset=UTF-8\nUser-Agent: native-http-client\nCookie: User-Agent=native-http-client; \n\n{\"Image\":\"nginx\"}\n```\n\n### 响应\n\nresponse 为字符串格式的原始响应值，例如 Json xml 等，可直接使用\n\n```golang\nresponse, err := client.Get(\"/containers/json\", nil)\nresponse, err := client.Put(\"/containers/create\", `{\"Image\":\"nginx\"}`)\n```\n\n### API\n\n携带 Header\n```golang\nclient.WithHeader(\"User-Agent\", \"native-http-client\")\n      .WithHeader(\"Token\", \"***\")\n      .WithHeader(\"...\", \"***\")\n```\n\n携带 Cookie    \n仅当 Header 中未设置 Cookie 字段时生效\n```golang\nclient.WithCookie(\"UserName\", \"alex\")\n      .WithCookie(\"UID\", \"***\")\n      .WithCookie(\"...\", \"***\")\n```\n\n[更多](http_client.go)\n\n响应：client.Response\n\n```javascript\n{\n    \"ContentType\": \"application/json\",\n    \"ContentLength\": 1054,\n    \"StatusCode\": 200,\n    \"Headers\": {\n        \"Connection\": \"close\",\n        \"Content-Length\": \"1054\",\n        \"Content-Type\": \"application/json\",\n        \"Date\": \"Wed, 14 Oct 2020 08:37:20 GMT\",\n        \"Server\": \"nginx/1.18.0\"\n    },\n    \"Cookies\": {},\n    \"Body\": \"{\\\"Status\\\":\\\"OK\\\",\\\"...\\\":\\\"...\\\"}\"\n}\n```\n\n\n### 核心原理\n\n对网络发送原始HTTP协议，以下为 POST API 对应的命令示例\n\nunix sock\n\n```shell\ncurl -s --unix-socket /var/run/docker.sock \\\n    -X POST http://localhost/containers/create?name=nginx \\\n    --data '{\"Image\":\"nginx\"}' \n```\n\ntcp\n```shell \ntelnet domain 80\nTrying xxxxxx...\nConnected to domain.\nEscape character is '^]'.\nPOST /containers/create?name=nginx HTTP/1.1\nHost: localhost\nConnection: close\nContent-Length: 17\nAccept: */*\nContent-Type: application/json;charset=UTF-8\nUser-Agent: native-http-client\nCookie: User-Agent=native-http-client; \n\n{\"Image\":\"nginx\"}\n```\n\n\n### 鸣谢\n\n- 本项目的实现一定程度上参考了 [ddliu/go-httpclient](https://github.com/ddliu/go-httpclient) 在此致谢\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fo8x%2Fnative-httpclient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fo8x%2Fnative-httpclient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fo8x%2Fnative-httpclient/lists"}