mirror of
https://github.com/tdlight-team/tdlight-telegram-bot-api.git
synced 2025-02-08 17:46:47 +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.
|
description: TCP port where the server is listening for incomming connections.
|
||||||
type: integer
|
type: integer
|
||||||
type:
|
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
|
type: string
|
||||||
username:
|
username:
|
||||||
description: Username used to authenticate against a Socks5 proxy.
|
description: Username used to authenticate against a Socks5/Http proxy.
|
||||||
type: string
|
type: string
|
||||||
password:
|
password:
|
||||||
description: Password used to authenticate against a Socks5 proxy.
|
description: Password used to authenticate against a Socks5/Http proxy.
|
||||||
type: string
|
type: string
|
||||||
secret:
|
secret:
|
||||||
description: Secret used to authenticate against an MTProto proxy.
|
description: Secret used to authenticate against an MTProto proxy.
|
||||||
type: string
|
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:
|
required:
|
||||||
- server
|
- server
|
||||||
- port
|
- port
|
||||||
@ -2155,17 +2158,20 @@ paths:
|
|||||||
description: TCP port where the server is listening for incomming connections.
|
description: TCP port where the server is listening for incomming connections.
|
||||||
type: integer
|
type: integer
|
||||||
type:
|
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
|
type: string
|
||||||
username:
|
username:
|
||||||
description: Username used to authenticate against a Socks5 proxy.
|
description: Username used to authenticate against a Socks5/Http proxy.
|
||||||
type: string
|
type: string
|
||||||
password:
|
password:
|
||||||
description: Password used to authenticate against a Socks5 proxy.
|
description: Password used to authenticate against a Socks5/Http proxy.
|
||||||
type: string
|
type: string
|
||||||
secret:
|
secret:
|
||||||
description: Secret used to authenticate against an MTProto proxy.
|
description: Secret used to authenticate against an MTProto proxy.
|
||||||
type: string
|
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:
|
required:
|
||||||
- server
|
- server
|
||||||
- port
|
- port
|
||||||
@ -2181,17 +2187,20 @@ paths:
|
|||||||
description: TCP port where the server is listening for incomming connections.
|
description: TCP port where the server is listening for incomming connections.
|
||||||
type: integer
|
type: integer
|
||||||
type:
|
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
|
type: string
|
||||||
username:
|
username:
|
||||||
description: Username used to authenticate against a Socks5 proxy.
|
description: Username used to authenticate against a Socks5/Http proxy.
|
||||||
type: string
|
type: string
|
||||||
password:
|
password:
|
||||||
description: Password used to authenticate against a Socks5 proxy.
|
description: Password used to authenticate against a Socks5/Http proxy.
|
||||||
type: string
|
type: string
|
||||||
secret:
|
secret:
|
||||||
description: Secret used to authenticate against an MTProto proxy.
|
description: Secret used to authenticate against an MTProto proxy.
|
||||||
type: string
|
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:
|
required:
|
||||||
- server
|
- server
|
||||||
- port
|
- port
|
||||||
@ -12438,7 +12447,7 @@ components:
|
|||||||
description: 'TCP port where the proxy server listens.'
|
description: 'TCP port where the proxy server listens.'
|
||||||
type: integer
|
type: integer
|
||||||
type:
|
type:
|
||||||
description: 'Type of proxy server, either socks5 or mtproto.'
|
description: 'Type of proxy server, either socks5, mtproto or http.'
|
||||||
type: string
|
type: string
|
||||||
username:
|
username:
|
||||||
description: 'Username to authenticate to the proxy server.'
|
description: 'Username to authenticate to the proxy server.'
|
||||||
@ -12449,6 +12458,9 @@ components:
|
|||||||
secret:
|
secret:
|
||||||
description: 'Secret to authenticate to the proxy server.'
|
description: 'Secret to authenticate to the proxy server.'
|
||||||
type: string
|
type: string
|
||||||
|
http_only:
|
||||||
|
description: 'Whether an Http proxy can only use Http requests (and does not support HTTP CONNECT method).'
|
||||||
|
type: boolean
|
||||||
required:
|
required:
|
||||||
- id
|
- id
|
||||||
- last_used_date
|
- last_used_date
|
||||||
|
@ -2719,6 +2719,15 @@ class Client::JsonProxy : public Jsonable {
|
|||||||
object("secret", ptype->secret_);
|
object("secret", ptype->secret_);
|
||||||
}
|
}
|
||||||
break;
|
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_user = query->arg("username");
|
||||||
auto proxy_pass = query->arg("password");
|
auto proxy_pass = query->arg("password");
|
||||||
type = td_api::make_object<td_api::proxyTypeSocks5>(proxy_user.str(), proxy_pass.str());
|
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 {
|
} else {
|
||||||
return Status::Error(400, "Unsupported proxy type");
|
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) {
|
td::Status Client::process_delete_proxy_query(PromisedQueryPtr &query) {
|
||||||
int32 pid = get_integer_arg(query.get(), "proxy_id", 0, 0);
|
auto arg_pid = query->arg("proxy_id");
|
||||||
if (pid == 0) {
|
if (arg_pid.empty()) {
|
||||||
return Status::Error(400, PSLICE() << "Invalid proxy_id specified");
|
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)));
|
std::make_unique<TdOnOkQueryCallback>(std::move(query)));
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
td::Status Client::process_enable_proxy_query(PromisedQueryPtr &query) {
|
td::Status Client::process_enable_proxy_query(PromisedQueryPtr &query) {
|
||||||
int32 pid = get_integer_arg(query.get(), "proxy_id", 0, 0);
|
auto arg_pid = query->arg("proxy_id");
|
||||||
if (pid == 0) {
|
if (arg_pid.empty()) {
|
||||||
return Status::Error(400, PSLICE() << "Invalid proxy_id specified");
|
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)));
|
std::make_unique<TdOnOkQueryCallback>(std::move(query)));
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user