@@ -186,6 +186,13 @@ impl Handler for Embed {
186
186
fn handle ( & self , request : Request ) -> Result < Response , Self :: Error > {
187
187
let docroot = self . docroot . clone ( ) ;
188
188
189
+ // Initialize the SAPI module
190
+ self . sapi . startup ( ) ?;
191
+
192
+ // Get REQUEST_URI _first_ as it needs the pre-rewrite state.
193
+ let url = request. url ( ) ;
194
+ let request_uri = url. path ( ) ;
195
+
189
196
// Apply request rewriting rules
190
197
let mut request = request. clone ( ) ;
191
198
if let Some ( rewriter) = & self . rewriter {
@@ -194,19 +201,15 @@ impl Handler for Embed {
194
201
. map_err ( EmbedRequestError :: RequestRewriteError ) ?;
195
202
}
196
203
197
- // Initialize the SAPI module
198
- self . sapi . startup ( ) ?;
204
+ let translated_path = translate_path ( & docroot, request. url ( ) . path ( ) ) ?
205
+ . display ( )
206
+ . to_string ( ) ;
199
207
200
- let url = request. url ( ) ;
201
-
202
- // Get original request URI and translate to final path
203
- // TODO: Should do this with request rewriting later...
204
- let request_uri = url. path ( ) ;
205
- let translated_path = translate_path ( & docroot, request_uri) ?. display ( ) . to_string ( ) ;
206
- let path_translated = cstr ( translated_path. clone ( ) )
207
- . map_err ( |_| EmbedRequestError :: FailedToSetRequestInfo ( "path_translated" . into ( ) ) ) ?;
208
+ // Convert REQUEST_URI and PATH_TRANSLATED to C strings
208
209
let request_uri = cstr ( request_uri)
209
210
. map_err ( |_| EmbedRequestError :: FailedToSetRequestInfo ( "request_uri" . into ( ) ) ) ?;
211
+ let path_translated = cstr ( translated_path. clone ( ) )
212
+ . map_err ( |_| EmbedRequestError :: FailedToSetRequestInfo ( "path_translated" . into ( ) ) ) ?;
210
213
211
214
// Extract request method, query string, and headers
212
215
let request_method = cstr ( request. method ( ) )
0 commit comments