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
1d5f0fe9
Commit
1d5f0fe9
authored
5 years ago
by
Nicolas Werner
Browse files
Options
Downloads
Patches
Plain Diff
Start typeerasing mtx::client to remove asio include
parent
3f3082e1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/mtxclient/http/client.hpp
+56
-50
56 additions, 50 deletions
include/mtxclient/http/client.hpp
with
56 additions
and
50 deletions
include/mtxclient/http/client.hpp
+
56
−
50
View file @
1d5f0fe9
...
...
@@ -463,73 +463,79 @@ template<class Response>
std
::
shared_ptr
<
mtx
::
http
::
Session
>
mtx
::
http
::
Client
::
create_session
(
HeadersCallback
<
Response
>
callback
)
{
auto
type_erased_cb
=
[
callback
](
const
HeaderFields
&
headers
,
const
std
::
string
&
body
,
const
boost
::
system
::
error_code
&
err_code
,
boost
::
beast
::
http
::
status
status_code
)
{
Response
response_data
;
mtx
::
http
::
ClientError
client_error
;
if
(
err_code
)
{
client_error
.
error_code
=
err_code
;
return
callback
(
response_data
,
headers
,
client_error
);
}
// We only count 2xx status codes as success.
if
(
static_cast
<
int
>
(
status_code
)
<
200
||
static_cast
<
int
>
(
status_code
)
>=
300
)
{
client_error
.
status_code
=
status_code
;
// Try to parse the response in case we have an endpoint that
// doesn't return an error struct for non 200 requests.
try
{
response_data
=
client
::
utils
::
deserialize
<
Response
>
(
body
);
}
catch
(
const
nlohmann
::
json
::
exception
&
e
)
{
}
// The homeserver should return an error struct.
try
{
nlohmann
::
json
json_error
=
json
::
parse
(
body
);
mtx
::
errors
::
Error
matrix_error
=
json_error
;
client_error
.
matrix_error
=
matrix_error
;
return
callback
(
response_data
,
headers
,
client_error
);
}
catch
(
const
nlohmann
::
json
::
exception
&
e
)
{
client_error
.
parse_error
=
std
::
string
(
e
.
what
())
+
": "
+
body
;
return
callback
(
response_data
,
headers
,
client_error
);
}
}
// If we reach that point we most likely have a valid output from the
// homeserver.
try
{
auto
res
=
client
::
utils
::
deserialize
<
Response
>
(
body
);
callback
(
std
::
move
(
res
),
headers
,
{});
}
catch
(
const
nlohmann
::
json
::
exception
&
e
)
{
client_error
.
parse_error
=
std
::
string
(
e
.
what
())
+
": "
+
body
;
callback
(
response_data
,
headers
,
client_error
);
}
};
auto
session
=
std
::
make_shared
<
Session
>
(
std
::
ref
(
ios_
),
std
::
ref
(
ssl_ctx_
),
server_
,
port_
,
client
::
utils
::
random_token
(),
[
callback
](
RequestID
,
const
boost
::
beast
::
http
::
response
<
boost
::
beast
::
http
::
string_body
>
&
response
,
const
boost
::
system
::
error_code
&
err_code
)
{
Response
response_data
;
mtx
::
http
::
ClientError
client_error
;
[
type_erased_cb
](
RequestID
,
const
boost
::
beast
::
http
::
response
<
boost
::
beast
::
http
::
string_body
>
&
response
,
const
boost
::
system
::
error_code
&
err_code
)
{
const
auto
header
=
response
.
base
();
if
(
err_code
)
{
client_error
.
error_code
=
err_code
;
return
callback
(
response_data
,
header
,
client_error
);
return
type_erased_cb
(
header
,
""
,
err_code
,
{});
}
// Decompress the response.
const
auto
body
=
client
::
utils
::
decompress
(
boost
::
iostreams
::
array_source
{
response
.
body
().
data
(),
response
.
body
().
size
()},
header
[
"Content-Encoding"
].
to_string
());
const
int
status_code
=
static_cast
<
int
>
(
response
.
result
());
// We only count 2xx status codes as success.
if
(
status_code
<
200
||
status_code
>=
300
)
{
client_error
.
status_code
=
response
.
result
();
// Try to parse the response in case we have an endpoint that
// doesn't return an error struct for non 200 requests.
try
{
response_data
=
client
::
utils
::
deserialize
<
Response
>
(
body
);
}
catch
(
const
nlohmann
::
json
::
exception
&
e
)
{
}
// The homeserver should return an error struct.
try
{
nlohmann
::
json
json_error
=
json
::
parse
(
body
);
mtx
::
errors
::
Error
matrix_error
=
json_error
;
client_error
.
matrix_error
=
matrix_error
;
return
callback
(
response_data
,
header
,
client_error
);
}
catch
(
const
nlohmann
::
json
::
exception
&
e
)
{
client_error
.
parse_error
=
std
::
string
(
e
.
what
())
+
": "
+
body
;
return
callback
(
response_data
,
header
,
client_error
);
}
}
// If we reach that point we most likely have a valid output from the
// homeserver.
try
{
auto
res
=
client
::
utils
::
deserialize
<
Response
>
(
body
);
callback
(
std
::
move
(
res
),
header
,
{});
}
catch
(
const
nlohmann
::
json
::
exception
&
e
)
{
client_error
.
parse_error
=
std
::
string
(
e
.
what
())
+
": "
+
body
;
callback
(
response_data
,
header
,
client_error
);
}
type_erased_cb
(
header
,
body
,
err_code
,
response
.
result
());
},
[
callback
](
RequestID
,
const
boost
::
system
::
error_code
ec
)
{
Response
response_data
;
mtx
::
http
::
ClientError
client_error
;
client_error
.
error_code
=
ec
;
callback
(
response_data
,
{},
client_error
);
[
type_erased_cb
](
RequestID
,
const
boost
::
system
::
error_code
ec
)
{
type_erased_cb
(
std
::
nullopt
,
""
,
ec
,
{});
});
if
(
session
)
...
...
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