comparison Core/HttpServer/FilesystemHttpHandler.cpp @ 1014:40e5255e7dc5

integration plugins->mainline
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 10 Jul 2014 11:13:26 +0200
parents e078ea944089
children 8d1845feb277
comparison
equal deleted inserted replaced
991:2f76b92addd4 1014:40e5255e7dc5
54 const boost::filesystem::path& p) 54 const boost::filesystem::path& p)
55 { 55 {
56 namespace fs = boost::filesystem; 56 namespace fs = boost::filesystem;
57 57
58 output.SendOkHeader("text/html", false, 0, NULL); 58 output.SendOkHeader("text/html", false, 0, NULL);
59 output.SendString("<html>"); 59 output.SendBodyString("<html>");
60 output.SendString(" <body>"); 60 output.SendBodyString(" <body>");
61 output.SendString(" <h1>Subdirectories</h1>"); 61 output.SendBodyString(" <h1>Subdirectories</h1>");
62 output.SendString(" <ul>"); 62 output.SendBodyString(" <ul>");
63 63
64 if (uri.size() > 0) 64 if (uri.size() > 0)
65 { 65 {
66 std::string h = Toolbox::FlattenUri(uri) + "/.."; 66 std::string h = Toolbox::FlattenUri(uri) + "/..";
67 output.SendString("<li><a href=\"" + h + "\">..</a></li>"); 67 output.SendBodyString("<li><a href=\"" + h + "\">..</a></li>");
68 } 68 }
69 69
70 fs::directory_iterator end; 70 fs::directory_iterator end;
71 for (fs::directory_iterator it(p) ; it != end; ++it) 71 for (fs::directory_iterator it(p) ; it != end; ++it)
72 { 72 {
76 std::string f = it->path().filename(); 76 std::string f = it->path().filename();
77 #endif 77 #endif
78 78
79 std::string h = Toolbox::FlattenUri(uri) + "/" + f; 79 std::string h = Toolbox::FlattenUri(uri) + "/" + f;
80 if (fs::is_directory(it->status())) 80 if (fs::is_directory(it->status()))
81 output.SendString("<li><a href=\"" + h + "\">" + f + "</a></li>"); 81 output.SendBodyString("<li><a href=\"" + h + "\">" + f + "</a></li>");
82 } 82 }
83 83
84 output.SendString(" </ul>"); 84 output.SendBodyString(" </ul>");
85 output.SendString(" <h1>Files</h1>"); 85 output.SendBodyString(" <h1>Files</h1>");
86 output.SendString(" <ul>"); 86 output.SendBodyString(" <ul>");
87 87
88 for (fs::directory_iterator it(p) ; it != end; ++it) 88 for (fs::directory_iterator it(p) ; it != end; ++it)
89 { 89 {
90 #if BOOST_HAS_FILESYSTEM_V3 == 1 90 #if BOOST_HAS_FILESYSTEM_V3 == 1
91 std::string f = it->path().filename().string(); 91 std::string f = it->path().filename().string();
93 std::string f = it->path().filename(); 93 std::string f = it->path().filename();
94 #endif 94 #endif
95 95
96 std::string h = Toolbox::FlattenUri(uri) + "/" + f; 96 std::string h = Toolbox::FlattenUri(uri) + "/" + f;
97 if (fs::is_regular_file(it->status())) 97 if (fs::is_regular_file(it->status()))
98 output.SendString("<li><a href=\"" + h + "\">" + f + "</a></li>"); 98 output.SendBodyString("<li><a href=\"" + h + "\">" + f + "</a></li>");
99 } 99 }
100 100
101 output.SendString(" </ul>"); 101 output.SendBodyString(" </ul>");
102 output.SendString(" </body>"); 102 output.SendBodyString(" </body>");
103 output.SendString("</html>"); 103 output.SendBodyString("</html>");
104 } 104 }
105 105
106 106
107 FilesystemHttpHandler::FilesystemHttpHandler(const std::string& baseUri, 107 FilesystemHttpHandler::FilesystemHttpHandler(const std::string& baseUri,
108 const std::string& root) : pimpl_(new PImpl) 108 const std::string& root) : pimpl_(new PImpl)
118 throw OrthancException("The path does not point to a directory"); 118 throw OrthancException("The path does not point to a directory");
119 } 119 }
120 } 120 }
121 121
122 122
123 bool FilesystemHttpHandler::IsServedUri(const UriComponents& uri) 123 bool FilesystemHttpHandler::Handle(
124 {
125 return Toolbox::IsChildUri(pimpl_->baseUri_, uri);
126 }
127
128
129 void FilesystemHttpHandler::Handle(
130 HttpOutput& output, 124 HttpOutput& output,
131 HttpMethod method, 125 HttpMethod method,
132 const UriComponents& uri, 126 const UriComponents& uri,
133 const Arguments& headers, 127 const Arguments& headers,
134 const Arguments& arguments, 128 const Arguments& arguments,
135 const std::string&) 129 const std::string&)
136 { 130 {
131 if (!Toolbox::IsChildUri(pimpl_->baseUri_, uri))
132 {
133 // This URI is not served by this handler
134 return false;
135 }
136
137 if (method != HttpMethod_Get) 137 if (method != HttpMethod_Get)
138 { 138 {
139 output.SendMethodNotAllowedError("GET"); 139 output.SendMethodNotAllowedError("GET");
140 return; 140 return true;
141 } 141 }
142 142
143 namespace fs = boost::filesystem; 143 namespace fs = boost::filesystem;
144 144
145 fs::path p = pimpl_->root_; 145 fs::path p = pimpl_->root_;
162 } 162 }
163 else 163 else
164 { 164 {
165 output.SendHeader(HttpStatus_404_NotFound); 165 output.SendHeader(HttpStatus_404_NotFound);
166 } 166 }
167
168 return true;
167 } 169 }
168 } 170 }