@@ -445,6 +445,21 @@ fn apply_request_options(
445445 mut req : wreq:: RequestBuilder ,
446446 opts : & RHash ,
447447) -> Result < wreq:: RequestBuilder , magnus:: Error > {
448+ if let Some ( val) = hash_get_value ( opts, "emulation" ) ? {
449+ let ruby = unsafe { Ruby :: get_unchecked ( ) } ;
450+ if val. is_kind_of ( ruby. class_false_class ( ) ) {
451+ // emulation: false — no per-request emulation override
452+ } else if val. is_kind_of ( ruby. class_true_class ( ) ) {
453+ let opt = build_emulation_option ( DEFAULT_EMULATION , opts) ?;
454+ req = req. emulation ( opt) ;
455+ } else {
456+ let name: String = TryConvert :: try_convert ( val) ?;
457+ let emu = parse_emulation ( & name) ?;
458+ let opt = build_emulation_option ( emu, opts) ?;
459+ req = req. emulation ( opt) ;
460+ }
461+ }
462+
448463 if let Some ( hdr_hash) = hash_get_hash ( opts, "headers" ) ? {
449464 let hmap = hash_to_header_map ( & hdr_hash) ?;
450465 req = req. headers ( hmap) ;
@@ -499,21 +514,6 @@ fn apply_request_options(
499514 req = req. proxy ( proxy) ;
500515 }
501516
502- if let Some ( val) = hash_get_value ( opts, "emulation" ) ? {
503- let ruby = unsafe { Ruby :: get_unchecked ( ) } ;
504- if val. is_kind_of ( ruby. class_false_class ( ) ) {
505- // emulation: false — no per-request emulation override
506- } else if val. is_kind_of ( ruby. class_true_class ( ) ) {
507- let opt = build_emulation_option ( DEFAULT_EMULATION , opts) ?;
508- req = req. emulation ( opt) ;
509- } else {
510- let name: String = TryConvert :: try_convert ( val) ?;
511- let emu = parse_emulation ( & name) ?;
512- let opt = build_emulation_option ( emu, opts) ?;
513- req = req. emulation ( opt) ;
514- }
515- }
516-
517517 Ok ( req)
518518}
519519
0 commit comments