mirror of
https://github.com/tdlight-team/tdlight-telegram-bot-api.git
synced 2025-02-01 22:27:36 +01:00
Fix proxy_id validation and add HTTP proxy support
This commit is contained in:
parent
de37889af1
commit
74008ebce4
@ -2129,17 +2129,20 @@ paths:
|
||||
description: TCP port where the server is listening for incomming connections.
|
||||
type: integer
|
||||
type:
|
||||
description: Type of proxy to be added. Must be either `mtproto` or `socks5`. MTProto proxies must provide a `secret` and Socks5 proxies can a `username` and `password`.
|
||||
description: Type of proxy to be added. Must be either `mtproto`, `socks5` or `http`. MTProto proxies must provide a `secret` and Socks5/Http proxies can a `username` and `password`.
|
||||
type: string
|
||||
username:
|
||||
description: Username used to authenticate against a Socks5 proxy.
|
||||
description: Username used to authenticate against a Socks5/Http proxy.
|
||||
type: string
|
||||
password:
|
||||
description: Password used to authenticate against a Socks5 proxy.
|
||||
description: Password used to authenticate against a Socks5/Http proxy.
|
||||
type: string
|
||||
secret:
|
||||
description: Secret used to authenticate against an MTProto proxy.
|
||||
type: string
|
||||
http_only:
|
||||
description: Set to true if the proxy only supports HTTP requests (as opposed to transparent TCP connections via HTTP CONNECT).
|
||||
type: boolean
|
||||
required:
|
||||
- server
|
||||
- port
|
||||
@ -2155,17 +2158,20 @@ paths:
|
||||
description: TCP port where the server is listening for incomming connections.
|
||||
type: integer
|
||||
type:
|
||||
description: Type of proxy to be added. Must be either `mtproto` or `socks5`. MTProto proxies must provide a `secret` and Socks5 proxies can a `username` and `password`.
|
||||
description: Type of proxy to be added. Must be either `mtproto`, `socks5` or `http`. MTProto proxies must provide a `secret` and Socks5/Http proxies can a `username` and `password`.
|
||||
type: string
|
||||
username:
|
||||
description: Username used to authenticate against a Socks5 proxy.
|
||||
description: Username used to authenticate against a Socks5/Http proxy.
|
||||
type: string
|
||||
password:
|
||||
description: Password used to authenticate against a Socks5 proxy.
|
||||
description: Password used to authenticate against a Socks5/Http proxy.
|
||||
type: string
|
||||
secret:
|
||||
description: Secret used to authenticate against an MTProto proxy.
|
||||
type: string
|
||||
http_only:
|
||||
description: Set to true if the proxy only supports HTTP requests (as opposed to transparent TCP connections via HTTP CONNECT).
|
||||
type: boolean
|
||||
required:
|
||||
- server
|
||||
- port
|
||||
@ -2181,17 +2187,20 @@ paths:
|
||||
description: TCP port where the server is listening for incomming connections.
|
||||
type: integer
|
||||
type:
|
||||
description: Type of proxy to be added. Must be either `mtproto` or `socks5`. MTProto proxies must provide a `secret` and Socks5 proxies can a `username` and `password`.
|
||||
description: Type of proxy to be added. Must be either `mtproto`, `socks5` or `http`. MTProto proxies must provide a `secret` and Socks5/Http proxies can a `username` and `password`.
|
||||
type: string
|
||||
username:
|
||||
description: Username used to authenticate against a Socks5 proxy.
|
||||
description: Username used to authenticate against a Socks5/Http proxy.
|
||||
type: string
|
||||
password:
|
||||
description: Password used to authenticate against a Socks5 proxy.
|
||||
description: Password used to authenticate against a Socks5/Http proxy.
|
||||
type: string
|
||||
secret:
|
||||
description: Secret used to authenticate against an MTProto proxy.
|
||||
type: string
|
||||
http_only:
|
||||
description: Set to true if the proxy only supports HTTP requests (as opposed to transparent TCP connections via HTTP CONNECT).
|
||||
type: boolean
|
||||
required:
|
||||
- server
|
||||
- port
|
||||
@ -12438,7 +12447,7 @@ components:
|
||||
description: 'TCP port where the proxy server listens.'
|
||||
type: integer
|
||||
type:
|
||||
description: 'Type of proxy server, either socks5 or mtproto.'
|
||||
description: 'Type of proxy server, either socks5, mtproto or http.'
|
||||
type: string
|
||||
username:
|
||||
description: 'Username to authenticate to the proxy server.'
|
||||
@ -12449,6 +12458,9 @@ components:
|
||||
secret:
|
||||
description: 'Secret to authenticate to the proxy server.'
|
||||
type: string
|
||||
http_only:
|
||||
description: 'Whether an Http proxy can only use Http requests (and does not support HTTP CONNECT method).'
|
||||
type: boolean
|
||||
required:
|
||||
- id
|
||||
- last_used_date
|
||||
|
@ -2719,6 +2719,15 @@ class Client::JsonProxy : public Jsonable {
|
||||
object("secret", ptype->secret_);
|
||||
}
|
||||
break;
|
||||
case td_api::proxyTypeHttp::ID:
|
||||
{
|
||||
auto ptype = static_cast<td_api::proxyTypeHttp *>(proxy_->type_.get());
|
||||
object("type", "http");
|
||||
object("username", ptype->username_);
|
||||
object("password", ptype->password_);
|
||||
object("http_only", td::JsonBool(ptype->http_only_));
|
||||
}
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
@ -8757,6 +8766,11 @@ td::Status Client::process_add_proxy_query(PromisedQueryPtr &query) {
|
||||
auto proxy_user = query->arg("username");
|
||||
auto proxy_pass = query->arg("password");
|
||||
type = td_api::make_object<td_api::proxyTypeSocks5>(proxy_user.str(), proxy_pass.str());
|
||||
} else if (proxy_type == "http") {
|
||||
auto proxy_user = query->arg("username");
|
||||
auto proxy_pass = query->arg("password");
|
||||
auto proxy_http = query->arg("http_only");
|
||||
type = td_api::make_object<td_api::proxyTypeHttp>(proxy_user.str(), proxy_pass.str(), to_bool(proxy_http));
|
||||
} else {
|
||||
return Status::Error(400, "Unsupported proxy type");
|
||||
}
|
||||
@ -8767,23 +8781,23 @@ td::Status Client::process_add_proxy_query(PromisedQueryPtr &query) {
|
||||
}
|
||||
|
||||
td::Status Client::process_delete_proxy_query(PromisedQueryPtr &query) {
|
||||
int32 pid = get_integer_arg(query.get(), "proxy_id", 0, 0);
|
||||
if (pid == 0) {
|
||||
return Status::Error(400, PSLICE() << "Invalid proxy_id specified");
|
||||
auto arg_pid = query->arg("proxy_id");
|
||||
if (arg_pid.empty()) {
|
||||
return Status::Error(400, PSLICE() << "No proxy_id specified");
|
||||
}
|
||||
|
||||
send_request(make_object<td_api::removeProxy>(pid),
|
||||
send_request(make_object<td_api::removeProxy>(td::to_integer<int32>(arg_pid)),
|
||||
std::make_unique<TdOnOkQueryCallback>(std::move(query)));
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
td::Status Client::process_enable_proxy_query(PromisedQueryPtr &query) {
|
||||
int32 pid = get_integer_arg(query.get(), "proxy_id", 0, 0);
|
||||
if (pid == 0) {
|
||||
return Status::Error(400, PSLICE() << "Invalid proxy_id specified");
|
||||
auto arg_pid = query->arg("proxy_id");
|
||||
if (arg_pid.empty()) {
|
||||
return Status::Error(400, PSLICE() << "No proxy_id specified");
|
||||
}
|
||||
|
||||
send_request(make_object<td_api::enableProxy>(pid),
|
||||
send_request(make_object<td_api::enableProxy>(td::to_integer<int32>(arg_pid)),
|
||||
std::make_unique<TdOnOkQueryCallback>(std::move(query)));
|
||||
return Status::OK();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user