1 /*
2  * SessionUriHandlers.cpp
3  *
4  * Copyright (C) 2021 by RStudio, PBC
5  *
6  * Unless you have received this program directly from RStudio pursuant
7  * to the terms of a commercial license agreement with RStudio, then
8  * this program is licensed to you under the terms of version 3 of the
9  * GNU Affero General Public License. This program is distributed WITHOUT
10  * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
11  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
12  * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
13  *
14  */
15 
16 #include "SessionUriHandlers.hpp"
17 
18 #include <session/SessionConstants.hpp>
19 
20 using namespace rstudio::core;
21 
22 namespace rstudio {
23 namespace session {
24 namespace uri_handlers {
25 
handlers()26 http::UriHandlers& handlers()
27 {
28    static http::UriHandlers instance;
29    return instance;
30 }
31 
32 } // namespace uri_handlers
33 
34 namespace module_context {
35 
registerAsyncUriHandler(const std::string & name,const http::UriAsyncHandlerFunction & handlerFunction)36 Error registerAsyncUriHandler(
37                          const std::string& name,
38                          const http::UriAsyncHandlerFunction& handlerFunction)
39 {
40 
41    uri_handlers::handlers().add(http::UriHandler(name, handlerFunction));
42    return Success();
43 }
44 
registerUriHandler(const std::string & name,const http::UriHandlerFunction & handlerFunction)45 Error registerUriHandler(const std::string& name,
46                          const http::UriHandlerFunction& handlerFunction)
47 {
48    uri_handlers::handlers().add(http::UriHandler(name, handlerFunction));
49    return Success();
50 }
51 
registerUploadHandler(const std::string & name,const http::UriAsyncUploadHandlerFunction & handlerFunction)52 Error registerUploadHandler(const std::string& name,
53                             const http::UriAsyncUploadHandlerFunction& handlerFunction)
54 {
55    uri_handlers::handlers().add(http::UriHandler(name, handlerFunction));
56    return Success();
57 }
58 
registerAsyncLocalUriHandler(const std::string & name,const http::UriAsyncHandlerFunction & handlerFunction)59 Error registerAsyncLocalUriHandler(
60                          const std::string& name,
61                          const http::UriAsyncHandlerFunction& handlerFunction)
62 {
63    uri_handlers::handlers().add(http::UriHandler(kLocalUriLocationPrefix + name,
64                                       handlerFunction));
65    return Success();
66 }
67 
registerLocalUriHandler(const std::string & name,const http::UriHandlerFunction & handlerFunction)68 Error registerLocalUriHandler(const std::string& name,
69                               const http::UriHandlerFunction& handlerFunction)
70 {
71    uri_handlers::handlers().add(http::UriHandler(kLocalUriLocationPrefix + name,
72                                       handlerFunction));
73    return Success();
74 }
75 
76 } // namespace module_context
77 } // namespace session
78 } // namespace rstudio
79