rs_server_catalog/middleware/catalog_middleware.md
A BaseHTTPMiddleware to handle the user multi catalog.
The stac-fastapi software doesn't handle multi catalog. In the rs-server we need to handle user-based catalogs.
The rs-server uses only one catalog but the collections are prefixed by the user name. The middleware is used to hide this mechanism.
The middleware: * redirect the user-specific request to the common stac api endpoint * modifies the request to add the user prefix in the collection name * modifies the response to remove the user prefix in the collection name * modifies the response to update the links.
CatalogMiddleware
Bases: BaseHTTPMiddleware
Middleware entry point for the user-aware catalog facade.
A fresh UserCatalog handler is created for each request so mutable
request_ids state is never shared across concurrent requests.
Source code in docs/rs-server/services/catalog/rs_server_catalog/middleware/catalog_middleware.py
48 49 50 51 52 53 54 55 56 57 58 59 60 | |
dispatch(request, call_next)
async
Redirect the user catalog specific endpoint and adapt the response content.
Source code in docs/rs-server/services/catalog/rs_server_catalog/middleware/catalog_middleware.py
56 57 58 59 60 | |
UserCatalog
Per-request catalog middleware handler.
It collects caller/owner/collection/item identifiers, rewrites the incoming request to the internal pgstac route shape, delegates to stac-fastapi, then rewrites the response back to the public RS Server catalog API.
Source code in docs/rs-server/services/catalog/rs_server_catalog/middleware/catalog_middleware.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |
__init__(client)
Constructor, called from the middleware
Source code in docs/rs-server/services/catalog/rs_server_catalog/middleware/catalog_middleware.py
72 73 74 75 | |
dispatch(request, call_next)
async
Redirect the user catalog specific endpoint and adapt the response content.
The dispatch flow has three phases: 1. recover authentication and request identifiers, 2. let CatalogRequestManager rewrite/authorize the request, 3. let CatalogResponseManager adapt the backend response and side effects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
Request
|
Initial request |
required |
call_next
|
RequestResponseEndpoint
|
next call to apply |
required |
Returns:
| Name | Type | Description |
|---|---|---|
response |
Response
|
Response to the current request |
Source code in docs/rs-server/services/catalog/rs_server_catalog/middleware/catalog_middleware.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | |