Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
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
savoirfairelinux
opendht
Commits
2ca2835c
Commit
2ca2835c
authored
7 years ago
by
Sébastien Blin
Browse files
Options
Downloads
Patches
Plain Diff
add options method handler
parent
bbe922dd
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/opendht/dht_proxy_server.h
+8
-0
8 additions, 0 deletions
include/opendht/dht_proxy_server.h
src/dht_proxy_server.cpp
+20
-1
20 additions, 1 deletion
src/dht_proxy_server.cpp
with
28 additions
and
1 deletion
include/opendht/dht_proxy_server.h
+
8
−
0
View file @
2ca2835c
...
@@ -139,6 +139,14 @@ private:
...
@@ -139,6 +139,14 @@ private:
*/
*/
void
getFiltered
(
const
std
::
shared_ptr
<
restbed
::
Session
>&
session
)
const
;
void
getFiltered
(
const
std
::
shared_ptr
<
restbed
::
Session
>&
session
)
const
;
/**
* Respond allowed Methods
* Method: OPTIONS "/{hash: .*}"
* Return: HTTP 200 + Allow: allowed methods
* See https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS
*/
void
handleOptionsMethod
(
const
std
::
shared_ptr
<
restbed
::
Session
>&
session
)
const
;
std
::
thread
server_thread
{};
std
::
thread
server_thread
{};
std
::
unique_ptr
<
restbed
::
Service
>
service_
;
std
::
unique_ptr
<
restbed
::
Service
>
service_
;
std
::
shared_ptr
<
DhtRunner
>
dht_
;
std
::
shared_ptr
<
DhtRunner
>
dht_
;
...
...
This diff is collapsed.
Click to expand it.
src/dht_proxy_server.cpp
+
20
−
1
View file @
2ca2835c
...
@@ -81,6 +81,12 @@ DhtProxyServer::DhtProxyServer(std::shared_ptr<DhtRunner> dht, in_port_t port)
...
@@ -81,6 +81,12 @@ DhtProxyServer::DhtProxyServer(std::shared_ptr<DhtRunner> dht, in_port_t port)
}
}
);
);
#endif // OPENDHT_PROXY_SERVER_IDENTITY
#endif // OPENDHT_PROXY_SERVER_IDENTITY
resource
->
set_method_handler
(
"OPTIONS"
,
[
this
](
const
std
::
shared_ptr
<
restbed
::
Session
>
session
)
{
this
->
handleOptionsMethod
(
session
);
}
);
service_
->
publish
(
resource
);
service_
->
publish
(
resource
);
resource
=
std
::
make_shared
<
restbed
::
Resource
>
();
resource
=
std
::
make_shared
<
restbed
::
Resource
>
();
resource
->
set_path
(
"/{hash: .*}/{value: .*}"
);
resource
->
set_path
(
"/{hash: .*}/{value: .*}"
);
...
@@ -357,7 +363,7 @@ DhtProxyServer::putEncrypted(const std::shared_ptr<restbed::Session>& session) c
...
@@ -357,7 +363,7 @@ DhtProxyServer::putEncrypted(const std::shared_ptr<restbed::Session>& session) c
auto
value
=
std
::
make_shared
<
Value
>
(
root
);
auto
value
=
std
::
make_shared
<
Value
>
(
root
);
auto
toHash
=
request
->
get_path_parameter
(
"to"
);
auto
toHash
=
request
->
get_path_parameter
(
"to"
);
InfoHash
toInfoHash
(
toHash
);
InfoHash
toInfoHash
(
toHash
);
if
(
to
i
nfoHash
)
if
(
to
I
nfoHash
)
toInfoHash
=
InfoHash
::
get
(
toHash
);
toInfoHash
=
InfoHash
::
get
(
toHash
);
Json
::
FastWriter
writer
;
Json
::
FastWriter
writer
;
...
@@ -378,6 +384,19 @@ DhtProxyServer::putEncrypted(const std::shared_ptr<restbed::Session>& session) c
...
@@ -378,6 +384,19 @@ DhtProxyServer::putEncrypted(const std::shared_ptr<restbed::Session>& session) c
}
}
#endif // OPENDHT_PROXY_SERVER_IDENTITY
#endif // OPENDHT_PROXY_SERVER_IDENTITY
void
DhtProxyServer
::
handleOptionsMethod
(
const
std
::
shared_ptr
<
restbed
::
Session
>&
session
)
const
{
#if OPENDHT_PROXY_SERVER_IDENTITY
const
auto
allowed
=
"OPTIONS, GET, POST, LISTEN, SIGN, ENCRYPT"
;
#else
const
auto
allowed
=
"OPTIONS, GET, POST, LISTEN"
;
#endif //OPENDHT_PROXY_SERVER_IDENTITY
session
->
close
(
restbed
::
OK
,
{{
"Access-Control-Allow-Methods"
,
allowed
},
{
"Access-Control-Allow-Headers"
,
"content-type"
},
{
"Access-Control-Max-Age"
,
"86400"
}});
}
void
void
DhtProxyServer
::
getFiltered
(
const
std
::
shared_ptr
<
restbed
::
Session
>&
session
)
const
DhtProxyServer
::
getFiltered
(
const
std
::
shared_ptr
<
restbed
::
Session
>&
session
)
const
{
{
...
...
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