Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mtxclient
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
mtxclient
Commits
3d8f8686
Commit
3d8f8686
authored
4 years ago
by
Nicolas Werner
Browse files
Options
Downloads
Patches
Plain Diff
Follow redirects on well-known lookup
parent
eefc7e5f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/http/client.cpp
+51
-11
51 additions, 11 deletions
lib/http/client.cpp
with
51 additions
and
11 deletions
lib/http/client.cpp
+
51
−
11
View file @
3d8f8686
...
...
@@ -197,12 +197,19 @@ mtx::http::Client::get(const std::string &endpoint,
void
Client
::
set_server
(
const
std
::
string
&
server
)
{
std
::
string
server_name
=
server
;
std
::
string_view
server_name
=
server
;
int
port
=
443
;
// Remove https prefix, if it exists
if
(
boost
::
algorithm
::
starts_with
(
server_name
,
"https://"
))
boost
::
algorithm
::
erase_first
(
server_name
,
"https://"
);
if
(
server_name
.
substr
(
0
,
8
)
==
"https://"
)
{
server_name
.
remove_prefix
(
8
);
port
=
443
;
}
if
(
server_name
.
substr
(
0
,
7
)
==
"http://"
)
{
server_name
.
remove_prefix
(
7
);
port
=
80
;
}
if
(
server_name
.
size
()
>
0
&&
server_name
.
back
()
==
'/'
)
server_name
.
erase
(
server_name
.
end
()
-
1
);
server_name
.
remove_suffix
(
1
);
// Check if the input also contains the port.
std
::
vector
<
std
::
string
>
parts
;
...
...
@@ -213,6 +220,7 @@ Client::set_server(const std::string &server)
port_
=
std
::
stoi
(
parts
.
at
(
1
));
}
else
{
server_
=
server_name
;
port_
=
port
;
}
}
...
...
@@ -313,13 +321,45 @@ Client::login_sso_redirect(std::string redirectUrl)
void
Client
::
well_known
(
Callback
<
mtx
::
responses
::
WellKnown
>
callback
)
{
get
<
mtx
::
responses
::
WellKnown
>
(
"/matrix/client"
,
[
callback
](
const
mtx
::
responses
::
WellKnown
&
res
,
HeaderFields
,
RequestErr
err
)
{
callback
(
res
,
err
);
},
false
,
"/.well-known"
);
struct
DoLookup
{
void
operator
()(
const
mtx
::
responses
::
WellKnown
&
res
,
HeaderFields
headers
,
RequestErr
err
)
{
if
(
err
&&
(
err
->
status_code
==
boost
::
beast
::
http
::
status
::
found
||
err
->
status_code
==
boost
::
beast
::
http
::
status
::
moved_permanently
)
&&
numRedirects
<
30
&&
headers
&&
headers
->
count
(
boost
::
beast
::
http
::
field
::
location
))
{
numRedirects
++
;
auto
server
=
headers
.
value
()[
boost
::
beast
::
http
::
field
::
location
];
size_t
start_search
=
0
;
if
(
server
.
starts_with
(
"https://"
))
start_search
=
8
;
else
if
(
server
.
starts_with
(
"http://"
))
start_search
=
7
;
client
->
set_server
(
std
::
string
(
server
.
substr
(
0
,
server
.
find_first_of
(
'/'
,
start_search
))));
client
->
get
<
mtx
::
responses
::
WellKnown
>
(
"/matrix/client"
,
std
::
move
(
*
this
),
false
,
"/.well-known"
);
return
;
}
callback
(
res
,
err
);
}
Callback
<
mtx
::
responses
::
WellKnown
>
callback
;
int
numRedirects
=
0
;
Client
*
client
=
nullptr
;
}
func
;
func
.
numRedirects
=
0
;
func
.
callback
=
std
::
move
(
callback
);
func
.
client
=
this
;
get
<
mtx
::
responses
::
WellKnown
>
(
"/matrix/client"
,
std
::
move
(
func
),
false
,
"/.well-known"
);
}
void
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment