OdbDesign
OdbDesign ODB++ Parser - C++ library, gRPC/REST server, CLI, tests
 
Loading...
Searching...
No Matches
RouteController.h
Go to the documentation of this file.
1#pragma once
2
3#include "IOdbServerApp.h"
4#include "../odbdesign_export.h"
5#include <optional>
6#include <string>
7#include <functional>
8#include <memory>
9#include <vector>
10
11namespace Odb::Lib::App
12{
14 {
15 public:
16 virtual ~RouteController() = default;
17
18 virtual void register_routes() = 0;
19
20 typedef std::vector<std::shared_ptr<RouteController>> Vector;
21
22 protected:
24
26
27 typedef std::function<crow::response(const crow::request& req)> TRouteHandlerFunction;
28
29 void register_route_handler(std::string route, TRouteHandlerFunction handler);
30
31 crow::response makeLoadedFileModelsResponse(bool) const;
32
33 // ---- HTTP caching for per-design data GETs (M1.3) ----
34
35 // Conditional-GET support. Computes the design's strong ETag (see
36 // Utils/ETag.h: design name + archive mtime/size + endpoint path) BEFORE
37 // the archive is loaded or anything serialized; if the request's
38 // If-None-Match matches it, returns the 304 response (empty body, no
39 // serialization work — that is the point). Returns std::nullopt when the
40 // caller must proceed, with etag carrying the computed tag (empty when no
41 // archive file exists — the load will 404 and no caching headers go out).
42 // Call AFTER authentication and BEFORE any design loading.
43 std::optional<crow::response> checkConditionalGet(const crow::request& req,
44 const std::string& designName,
45 const std::string& endpointPath,
46 std::string& etag) const;
47
48 // Attaches ETag + Cache-Control to a successful data response. No-op when
49 // etag is empty (archive file not found/statable).
50 crow::response withCacheHeaders(crow::response response, const std::string& etag) const;
51
52 constexpr inline static const char* CACHE_CONTROL_DATA_VALUE = "private, max-age=3600";
53
54 };
55}
56
virtual void register_routes()=0
std::function< crow::response(const crow::request &req)> TRouteHandlerFunction
std::vector< std::shared_ptr< RouteController > > Vector
virtual ~RouteController()=default
#define ODBDESIGN_EXPORT