@@ -156,36 +156,34 @@ static
156156void
157157path_cat (
158158 std::string& result,
159- core::string_view base ,
160- core::string_view path )
159+ core::string_view prefix ,
160+ urls::segments_view suffix )
161161{
162- if (base.empty ())
163- {
164- result = path;
165- return ;
166- }
167- result = base;
162+ result = prefix;
168163
169164#ifdef BOOST_MSVC
170165 char constexpr path_separator = ' \\ ' ;
171- if (result.back () == path_separator)
172- result.resize (result.size () - 1 );
173- result.append (path.data (), path.size ());
174- for (auto & c : result)
175- if (c == ' /' )
176- c = path_separator;
177166#else
178167 char constexpr path_separator = ' /' ;
179- if (result.back () == path_separator)
180- result.resize (result.size () - 1 );
181- result.append (path.data (), path.size ());
182168#endif
169+ if ( result.back () == path_separator)
170+ result.resize (result.size () - 1 ); // remove trailing
171+ #ifdef BOOST_MSVC
172+ for (auto & c : result)
173+ if ( c == ' /' )
174+ c = path_separator;
175+ #endif
176+ for (auto const & seg : suffix)
177+ {
178+ result.push_back (path_separator);
179+ result.append (seg);
180+ }
183181}
184182
185183// ------------------------------------------------
186184
187185static
188- void
186+ bool
189187make_error_response (
190188 http_proto::status code,
191189 http_proto::request_base const & req,
@@ -244,10 +242,12 @@ make_error_response(
244242
245243 sr.start (res, http_proto::string_body (
246244 std::move (body)));
245+
246+ return false ;
247247}
248248
249249static
250- void
250+ bool
251251service_unavailable (
252252 http_proto::response& res,
253253 http_proto::serializer& sr,
@@ -294,18 +294,20 @@ service_unavailable(
294294 res,
295295 http_proto::string_body (
296296 std::move (s)));
297+ return false ;
297298}
298299
299300// ------------------------------------------------
300301
301- void
302+ bool
302303file_responder::
303304operator ()(
304- handler_params& params) const
305+ Request& req,
306+ Response& res) const
305307{
306- if (params .is_shutting_down )
308+ if (req .is_shutting_down )
307309 return service_unavailable (
308- params .res , params. serializer , params .req );
310+ res .res , res. sr , req .req );
309311
310312#if 0
311313 // Returns a server error response
@@ -323,17 +325,15 @@ operator()(
323325#endif
324326
325327 // Request path must be absolute and not contain "..".
326- if ( params .req .target ().empty () ||
327- params .req .target ()[0 ] != ' /' ||
328- params .req .target ().find (" .." ) != core::string_view::npos)
328+ if ( req .req .target ().empty () ||
329+ req .req .target ()[0 ] != ' /' ||
330+ req .req .target ().find (" .." ) != core::string_view::npos)
329331 return make_error_response (http_proto::status::bad_request,
330- params .req , params .res , params. serializer );
332+ req .req , res .res , res. sr );
331333
332334 // Build the path to the requested file
333335 std::string path;
334- path_cat (path, doc_root_, params.req .target ());
335- if (params.req .target ().back () == ' /' )
336- path.append (" index.html" );
336+ path_cat (path, doc_root_, req.path );
337337
338338 // Attempt to open the file
339339 system::error_code ec;
@@ -344,52 +344,55 @@ operator()(
344344 size = f.size (ec);
345345 if (! ec.failed ())
346346 {
347- params .res .set_start_line (
347+ res .res .set_start_line (
348348 http_proto::status::ok,
349- params .req .version ());
350- params .res .set (http_proto::field::server, " Boost" );
351- params .res .set_keep_alive (params .req .keep_alive ());
352- params .res .set_payload_size (size);
349+ req .req .version ());
350+ res .res .set (http_proto::field::server, " Boost" );
351+ res .res .set_keep_alive (req .req .keep_alive ());
352+ res .res .set_payload_size (size);
353353
354354 auto mt = mime_type (get_extension (path));
355- params .res .append (
355+ res .res .append (
356356 http_proto::field::content_type, mt);
357357
358- params. serializer .start <http_proto::file_source>(
359- params .res , std::move (f), size);
360- return ;
358+ res. sr .start <http_proto::file_source>(
359+ res .res , std::move (f), size);
360+ return false ;
361361 }
362362
363363 if (ec == system::errc::no_such_file_or_directory)
364364 return make_error_response (
365365 http_proto::status::not_found,
366- params .req , params .res , params. serializer );
366+ req .req , res .res , res. sr );
367367
368368 // ec.message()?
369369 return make_error_response (
370370 http_proto::status::internal_server_error,
371- params .req , params .res , params. serializer );
371+ req .req , res .res , res. sr );
372372}
373373
374374// ------------------------------------------------
375375
376- void
376+ bool
377377https_redirect_responder::
378- operator ()(handler_params& params) const
378+ operator ()(
379+ Request& req,
380+ Response& res) const
379381{
380- if (params .is_shutting_down )
382+ if (req .is_shutting_down )
381383 return service_unavailable (
382- params .res , params. serializer , params .req );
384+ res .res , res. sr , req .req );
383385
384386 std::string body;
385- prepare_error (params .res , body,
386- http_proto::status::moved_permanently, params .req );
387- urls::url u1 (params .req .target ());
387+ prepare_error (res .res , body,
388+ http_proto::status::moved_permanently, req .req );
389+ urls::url u1 (req .req .target ());
388390 u1.set_scheme_id (urls::scheme::https);
389391 u1.set_host_address (" localhost" ); // VFALCO WTF IS THIS!
390- params .res .append (http_proto::field::location, u1.buffer ());
391- params. serializer .start (params .res ,
392+ res .res .append (http_proto::field::location, u1.buffer ());
393+ res. sr .start (res .res ,
392394 http_proto::string_body ( std::move (body)));
395+ return false ;
393396}
394397
395398} // http_io
0 commit comments