@@ -109,6 +109,7 @@ def is_archivo_ontology_request(wrapped_request):
109
109
if request_path .endswith ("/" ):
110
110
request_path = request_path .rstrip ("/" )
111
111
if (request_host , request_path ) in ARCHIVO_PARSED_URLS :
112
+ wrapped_request .set_request_path (request_path )
112
113
logger .info (f"Requested URL: { request_host + request_path } is in Archivo" )
113
114
return True
114
115
@@ -117,17 +118,27 @@ def is_archivo_ontology_request(wrapped_request):
117
118
path_parts = request_path .split ("/" )
118
119
new_path = "/" .join (path_parts [:- 1 ])
119
120
120
- if ((request_host , new_path ) in ARCHIVO_PARSED_URLS ) or (
121
- (request_host , new_path + "/" ) in ARCHIVO_PARSED_URLS
122
- ):
123
- logger .info (f"Requested URL: { request_host + request_path } is in Archivo" )
121
+ if (request_host , new_path ) in ARCHIVO_PARSED_URLS :
122
+ wrapped_request .set_request_path (new_path )
123
+ logger .info (f"Requested URL: { request_host + new_path } is in Archivo" )
124
+ return True
125
+
126
+ new_path = new_path + "/"
127
+ if (request_host , new_path ) in ARCHIVO_PARSED_URLS :
128
+ wrapped_request .set_request_path (new_path )
129
+ logger .info (f"Requested URL: { request_host + new_path } is in Archivo" )
124
130
return True
125
131
126
132
new_path = "/" .join (path_parts [:- 2 ])
127
- if ((request_host , new_path ) in ARCHIVO_PARSED_URLS ) or (
128
- (request_host , new_path + "/" ) in ARCHIVO_PARSED_URLS
129
- ):
130
- logger .info (f"Requested URL: { request_host + request_path } is in Archivo" )
133
+ if (request_host , new_path ) in ARCHIVO_PARSED_URLS :
134
+ wrapped_request .set_request_path (new_path )
135
+ logger .info (f"Requested URL: { request_host + new_path } is in Archivo" )
136
+ return True
137
+
138
+ new_path = new_path + "/"
139
+ if (request_host , new_path ) in ARCHIVO_PARSED_URLS :
140
+ wrapped_request .set_request_path (new_path )
141
+ logger .info (f"Requested URL: { request_host + new_path } is in Archivo" )
131
142
return True
132
143
133
144
logger .info (f"Requested URL: { request_host + request_path } is NOT in Archivo" )
@@ -140,7 +151,7 @@ def request_ontology(url, headers, disableRemovingRedirects=False, timeout=5):
140
151
response = requests .get (
141
152
url = url , headers = headers , allow_redirects = allow_redirects , timeout = 5
142
153
)
143
- logger .info ("Successfully fetched original ontology" )
154
+ logger .info ("Successfully fetched ontology" )
144
155
return response
145
156
except Exception as e :
146
157
logger .error (f"Error fetching original ontology: { e } " )
@@ -154,7 +165,6 @@ def proxy_logic(wrapped_request, config):
154
165
set_onto_format_headers (wrapped_request , config )
155
166
156
167
headers = wrapped_request .get_request_headers ()
157
- ontology , _ , _ = wrapped_request .get_request_url_host_path ()
158
168
159
169
# if the requested format is not in Archivo and the ontoVersion is not original
160
170
# we can stop because the archivo request will not go through
@@ -164,15 +174,16 @@ def proxy_logic(wrapped_request, config):
164
174
return mock_response_500
165
175
166
176
if config .ontoVersion == OntoVersion .ORIGINAL :
177
+ ontology , _ , _ = wrapped_request .get_request_url_host_path ()
167
178
response = fetch_original (ontology , headers , config )
168
179
elif config .ontoVersion == OntoVersion .ORIGINAL_FAILOVER_LIVE_LATEST :
169
180
response = fetch_failover (
170
- wrapped_request , ontology , headers , config .disableRemovingRedirects
181
+ wrapped_request , headers , config .disableRemovingRedirects
171
182
)
172
183
elif config .ontoVersion == OntoVersion .LATEST_ARCHIVED :
173
184
response = fetch_latest_archived (wrapped_request , ontology , headers )
174
185
elif config .ontoVersion == OntoVersion .LATEST_ARCHIVED :
175
- response = fetch_timestamp_archived (wrapped_request , ontology , headers , config )
186
+ response = fetch_timestamp_archived (wrapped_request , headers , config )
176
187
# Commenting the manifest related part because it is not supported in the current version
177
188
# elif ontoVersion == 'dependencyManifest':
178
189
# response = fetch_dependency_manifest(ontology, headers, manifest)
@@ -187,7 +198,8 @@ def fetch_original(ontology, headers, disableRemovingRedirects):
187
198
188
199
189
200
# Failover mode
190
- def fetch_failover (wrapped_request , ontology , headers , disableRemovingRedirects ):
201
+ def fetch_failover (wrapped_request , headers , disableRemovingRedirects ):
202
+ ontology , _ , _ = wrapped_request .get_request_url_host_path ()
191
203
logger .info (f"Fetching original ontology with failover from URL: { ontology } " )
192
204
original_response = request_ontology (ontology , headers , disableRemovingRedirects )
193
205
if original_response .status_code in passthrough_status_codes :
@@ -204,36 +216,38 @@ def fetch_failover(wrapped_request, ontology, headers, disableRemovingRedirects)
204
216
return original_response
205
217
else :
206
218
logging .info (f"The returned type is not the same as the requested one" )
207
- return fetch_latest_archived (wrapped_request , ontology , headers )
219
+ return fetch_latest_archived (wrapped_request , headers )
208
220
else :
209
221
logger .info (
210
222
f"The returend status code is not accepted: { original_response .status_code } "
211
223
)
212
- return fetch_latest_archived (wrapped_request , ontology , headers )
224
+ return fetch_latest_archived (wrapped_request , headers )
213
225
214
226
215
227
# Fetch the lates version from archivo (no timestamp defined)
216
- def fetch_latest_archived (wrapped_request , ontology , headers ):
228
+ def fetch_latest_archived (wrapped_request , headers ):
217
229
if not is_archivo_ontology_request (wrapped_request ):
218
230
logger .info (
219
231
"Data needs to be fetched from Archivo, but ontology is not available on Archivo."
220
232
)
221
233
return mock_response_404 ()
222
234
logger .info ("Fetch latest archived" )
223
235
format = get_format_from_accept_header (headers )
236
+ ontology , _ , _ = wrapped_request .get_request_url_host_path ()
224
237
dbpedia_url = f"{ archivo_api } ?o={ ontology } &f={ format } "
225
238
logger .info (f"Fetching from DBpedia Archivo API: { dbpedia_url } " )
226
239
return request_ontology (dbpedia_url , headers )
227
240
228
241
229
- def fetch_timestamp_archived (wrapped_request , ontology , headers , config ):
242
+ def fetch_timestamp_archived (wrapped_request , headers , config ):
230
243
if not is_archivo_ontology_request (wrapped_request ):
231
244
logger .info (
232
245
"Data needs to be fetched from Archivo, but ontology is not available on Archivo."
233
246
)
234
247
return mock_response_404 ()
235
248
logger .info ("Fetch archivo timestamp" )
236
249
format = get_format_from_accept_header (headers )
250
+ ontology , _ , _ = wrapped_request .get_request_url_host_path ()
237
251
dbpedia_url = f"{ archivo_api } ?o={ ontology } &f={ format } &v={ config .timestamp } "
238
252
logger .info (f"Fetching from DBpedia Archivo API: { dbpedia_url } " )
239
253
return request_ontology (dbpedia_url , headers )
0 commit comments