Mercurial > hg > orthanc
comparison Core/HttpServer/FilesystemHttpHandler.cpp @ 1113:ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 02 Sep 2014 15:51:20 +0200 |
parents | 8d1845feb277 |
children | 6e7e5ed91c2d |
comparison
equal
deleted
inserted
replaced
1112:a119f9ae3640 | 1113:ba5c0908600c |
---|---|
53 const UriComponents& uri, | 53 const UriComponents& uri, |
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.SetContentType("text/html"); |
59 output.SendBodyString("<html>"); | 59 |
60 output.SendBodyString(" <body>"); | 60 std::string s; |
61 output.SendBodyString(" <h1>Subdirectories</h1>"); | 61 s += "<html>"; |
62 output.SendBodyString(" <ul>"); | 62 s += " <body>"; |
63 s += " <h1>Subdirectories</h1>"; | |
64 s += " <ul>"; | |
63 | 65 |
64 if (uri.size() > 0) | 66 if (uri.size() > 0) |
65 { | 67 { |
66 std::string h = Toolbox::FlattenUri(uri) + "/.."; | 68 std::string h = Toolbox::FlattenUri(uri) + "/.."; |
67 output.SendBodyString("<li><a href=\"" + h + "\">..</a></li>"); | 69 s += "<li><a href=\"" + h + "\">..</a></li>"; |
68 } | 70 } |
69 | 71 |
70 fs::directory_iterator end; | 72 fs::directory_iterator end; |
71 for (fs::directory_iterator it(p) ; it != end; ++it) | 73 for (fs::directory_iterator it(p) ; it != end; ++it) |
72 { | 74 { |
76 std::string f = it->path().filename(); | 78 std::string f = it->path().filename(); |
77 #endif | 79 #endif |
78 | 80 |
79 std::string h = Toolbox::FlattenUri(uri) + "/" + f; | 81 std::string h = Toolbox::FlattenUri(uri) + "/" + f; |
80 if (fs::is_directory(it->status())) | 82 if (fs::is_directory(it->status())) |
81 output.SendBodyString("<li><a href=\"" + h + "\">" + f + "</a></li>"); | 83 s += "<li><a href=\"" + h + "\">" + f + "</a></li>"; |
82 } | 84 } |
83 | 85 |
84 output.SendBodyString(" </ul>"); | 86 s += " </ul>"; |
85 output.SendBodyString(" <h1>Files</h1>"); | 87 s += " <h1>Files</h1>"; |
86 output.SendBodyString(" <ul>"); | 88 s += " <ul>"; |
87 | 89 |
88 for (fs::directory_iterator it(p) ; it != end; ++it) | 90 for (fs::directory_iterator it(p) ; it != end; ++it) |
89 { | 91 { |
90 #if BOOST_HAS_FILESYSTEM_V3 == 1 | 92 #if BOOST_HAS_FILESYSTEM_V3 == 1 |
91 std::string f = it->path().filename().string(); | 93 std::string f = it->path().filename().string(); |
93 std::string f = it->path().filename(); | 95 std::string f = it->path().filename(); |
94 #endif | 96 #endif |
95 | 97 |
96 std::string h = Toolbox::FlattenUri(uri) + "/" + f; | 98 std::string h = Toolbox::FlattenUri(uri) + "/" + f; |
97 if (fs::is_regular_file(it->status())) | 99 if (fs::is_regular_file(it->status())) |
98 output.SendBodyString("<li><a href=\"" + h + "\">" + f + "</a></li>"); | 100 s += "<li><a href=\"" + h + "\">" + f + "</a></li>"; |
99 } | 101 } |
100 | 102 |
101 output.SendBodyString(" </ul>"); | 103 s += " </ul>"; |
102 output.SendBodyString(" </body>"); | 104 s += " </body>"; |
103 output.SendBodyString("</html>"); | 105 s += "</html>"; |
106 | |
107 output.SendBody(s); | |
104 } | 108 } |
105 | 109 |
106 | 110 |
107 FilesystemHttpHandler::FilesystemHttpHandler(const std::string& baseUri, | 111 FilesystemHttpHandler::FilesystemHttpHandler(const std::string& baseUri, |
108 const std::string& root) : pimpl_(new PImpl) | 112 const std::string& root) : pimpl_(new PImpl) |
160 { | 164 { |
161 OutputDirectoryContent(output, uri, p); | 165 OutputDirectoryContent(output, uri, p); |
162 } | 166 } |
163 else | 167 else |
164 { | 168 { |
165 output.SendHeader(HttpStatus_404_NotFound); | 169 output.SendStatus(HttpStatus_404_NotFound); |
166 } | 170 } |
167 | 171 |
168 return true; | 172 return true; |
169 } | 173 } |
170 } | 174 } |