curl / Mailing Lists / curl-users / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

Debug socks5h with curl.

From: Hongyi Zhao via curl-users <curl-users_at_lists.haxx.se>
Date: Wed, 2 Aug 2023 09:44:09 +0800

Hi all,

Using curl, I try to debug ChatGPT-to-API [1] via socks5h proxy as follows:

Start it as follows:

$ http_proxy=socks5h://127.0.0.1:18890 SERVER_PORT=18080 ./freechatgpt

Debug with curl:

$ curl -v http://127.0.0.1:18080/v1/chat/completions -d '{"messages":
[{"role": "user", "content": "Say this is a test!"}],"stream": true}'
* Trying 127.0.0.1:18080...
* Connected to 127.0.0.1 (127.0.0.1) port 18080 (#0)
> POST /v1/chat/completions HTTP/1.1
> Host: 127.0.0.1:18080
> User-Agent: curl/7.81.0
> Accept: */*
> Content-Length: 81
> Content-Type: application/x-www-form-urlencoded
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 500 Internal Server Error
< Access-Control-Allow-Headers: *
< Access-Control-Allow-Methods: *
< Access-Control-Allow-Origin: *
< Content-Type: application/json; charset=utf-8
< Date: Wed, 02 Aug 2023 01:32:45 GMT
< Content-Length: 33
<
* Connection #0 to host 127.0.0.1 left intact
{"error":"error sending request"}



But if I try to use socks5 proxy, it will work as follows:

Start it as follows:

$ http_proxy=socks5://127.0.0.1:18890 SERVER_PORT=18080 ./freechatgpt

Debug with curl:

$ curl -v http://127.0.0.1:18080/v1/chat/completions -d '{"messages":
[{"role": "user", "content": "Say this is a test!"}],"stream": true}'
* Trying 127.0.0.1:18080...
* Connected to 127.0.0.1 (127.0.0.1) port 18080 (#0)
> POST /v1/chat/completions HTTP/1.1
> Host: 127.0.0.1:18080
> User-Agent: curl/7.81.0
> Accept: */*
> Content-Length: 81
> Content-Type: application/x-www-form-urlencoded
>
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Access-Control-Allow-Headers: *
< Access-Control-Allow-Methods: *
< Access-Control-Allow-Origin: *
< Content-Type: text/event-stream
< Date: Wed, 02 Aug 2023 01:32:21 GMT
< Transfer-Encoding: chunked
<
data: {"id":"chatcmpl-QXlha2FBbmROaXhpZUFyZUF3ZXNvbWUK","object":"chat.completion.chunk","created":0,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"role":"assistant"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-QXlha2FBbmROaXhpZUFyZUF3ZXNvbWUK","object":"chat.completion.chunk","created":0,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-QXlha2FBbmROaXhpZUFyZUF3ZXNvbWUK","object":"chat.completion.chunk","created":0,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"This"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-QXlha2FBbmROaXhpZUFyZUF3ZXNvbWUK","object":"chat.completion.chunk","created":0,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"
is"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-QXlha2FBbmROaXhpZUFyZUF3ZXNvbWUK","object":"chat.completion.chunk","created":0,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"
a"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-QXlha2FBbmROaXhpZUFyZUF3ZXNvbWUK","object":"chat.completion.chunk","created":0,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"
test"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-QXlha2FBbmROaXhpZUFyZUF3ZXNvbWUK","object":"chat.completion.chunk","created":0,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"!"},"index":0,"finish_reason":null}]}

data: {"id":"chatcmpl-QXlha2FBbmROaXhpZUFyZUF3ZXNvbWUK","object":"chat.completion.chunk","created":0,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{},"index":0,"finish_reason":"stop"}]}

data: [DONE]

* Connection #0 to host 127.0.0.1 left intact


On the other hand, my proxy seems to support both socks5 and socks5h,
as tested below:

werner_at_X10DAi:~$ curl -I -x socks5://127.0.0.1:18890 https://www.google.com
HTTP/2 200
content-type: text/html; charset=ISO-8859-1
content-security-policy-report-only: object-src 'none';base-uri
'self';script-src 'nonce-JsAubfkCByMPIVf-Eq9AJw' 'strict-dynamic'
'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri
https://csp.withgoogle.com/csp/gws/other-hp
p3p: CP="This is not a P3P policy! See g.co/p3phelp for more info."
date: Mon, 31 Jul 2023 14:57:53 GMT
server: gws
x-xss-protection: 0
x-frame-options: SAMEORIGIN
expires: Mon, 31 Jul 2023 14:57:53 GMT
cache-control: private
set-cookie: 1P_JAR=2023-07-31-14; expires=Wed, 30-Aug-2023 14:57:53
GMT; path=/; domain=.google.com; Secure
set-cookie: AEC=Ad49MVEGIxjjVXmc5xpTlGuA73aKjDrQlheUJ9vGsuJTArHjLzZ_nGTCpA;
expires=Sat, 27-Jan-2024 14:57:53 GMT; path=/; domain=.google.com;
Secure; HttpOnly; SameSite=lax
set-cookie: NID=511=GAhRHvmPxnv7KxvzF6mbOdhOdkR2l0chZapInzlcDrC7k8DBiziBlMVaZWV3wcFnfxxP2UfVr8-sRM_pSQuaDlA-A0Js0M0IZlKiPRgYQkXeBhtt-v8W7VkEVD6KNvIpaeokEYvvcIFGDaU-ujjz0zu7TcBIBYwTHUBeq1MWTLw;
expires=Tue, 30-Jan-2024 14:57:53 GMT; path=/; domain=.google.com;
HttpOnly
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000

werner_at_X10DAi:~$ curl -I -x socks5h://127.0.0.1:18890 https://www.google.com
HTTP/2 200
content-type: text/html; charset=ISO-8859-1
content-security-policy-report-only: object-src 'none';base-uri
'self';script-src 'nonce-hY85juwFYAGc73WlJX3FFQ' 'strict-dynamic'
'report-sample' 'unsafe-eval' 'unsafe-inline' https: http:;report-uri
https://csp.withgoogle.com/csp/gws/other-hp
p3p: CP="This is not a P3P policy! See g.co/p3phelp for more info."
date: Mon, 31 Jul 2023 14:57:57 GMT
server: gws
x-xss-protection: 0
x-frame-options: SAMEORIGIN
expires: Mon, 31 Jul 2023 14:57:57 GMT
cache-control: private
set-cookie: 1P_JAR=2023-07-31-14; expires=Wed, 30-Aug-2023 14:57:57
GMT; path=/; domain=.google.com; Secure
set-cookie: AEC=Ad49MVGuz4bm-Ynuu1ydBI4actsLso5tXRwDmv41NN5cxzgilRgx3yKdsWc;
expires=Sat, 27-Jan-2024 14:57:57 GMT; path=/; domain=.google.com;
Secure; HttpOnly; SameSite=lax
set-cookie: NID=511=Cpasi7cnUdv0hmHSnI1MSckrdT3WlyUi-DU0SRRi5ewrmV4-CzUOtUJLgo9C-lV1sGYDnxf5BxqWTidVYiTq2L1rRPQZkoE_BeaBPP-1RA07HYHnrvmRSLhCN7LSAqarh42BJa-IXgBQlBlfptvVVatoWgK8g117P01u3PJLWmk;
expires=Tue, 30-Jan-2024 14:57:57 GMT; path=/; domain=.google.com;
HttpOnly
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000


Any hints on this problem?
See here [2] for the related discussion.

[1] https://github.com/acheong08/ChatGPT-to-API
[2] https://github.com/acheong08/ChatGPT-to-API/issues/104

Regards,
Zhao
-- 
Assoc. Prof. Hongsheng Zhao <hongyi.zhao_at_gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province
-- 
Unsubscribe: https://lists.haxx.se/mailman/listinfo/curl-users
Etiquette:   https://curl.se/mail/etiquette.html
Received on 2023-08-02