http-rs / http-rs/surf

Relative URL support

Open
#314 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
1.5k
Forks
128
PR merge metrics
No merged PRs in 30d

Description

I am trying to use `surf` to call my backend from a Yew-based WASM frontend running in the browser.

HTTP calls to the backend are typically performed by a frontend application using relative URLs; anyway, this is not possible with `surf` as every attempt to send a call with a relative URL generates a panic with this message in the browser console:
```
panicked at 'called `Result::unwrap()` on an `Err` value: RelativeUrlWithoutBase', /home/ufo/.cargo/registry/src/github.com-1ecc6299db9ec823/surf-2.2.0/src/client.rs:548:42

Stack:

init/imports.wbg.__wbg_new_59cb74e423758ede@http://127.0.0.1:3000/index-3c6d44c9390fc4f2.js:302:19
console_error_panic_hook::Error::new::hd990297f532a9234@http://127.0.0.1:3000/index-3c6d44c9390fc4f2_bg.wasm:wasm-function[7058]:0x186a2c
console_error_panic_hook::hook_impl::h80677aeedc307843@http://127.0.0.1:3000/index-3c6d44c9390fc4f2_bg.wasm:wasm-function[793]:0xb2e8a
console_error_panic_hook::hook::h1ee90794f5cd7865@http://127.0.0.1:3000/index-3c6d44c9390fc4f2_bg.wasm:wasm-function[7797]:0x190de1
core::ops::function::Fn::call::h474424fdd5f0e50d@http://127.0.0.1:3000/index-3c6d44c9390fc4f2_bg.wasm:wasm-function[6506]:0x17e209
std::panicking::rust_panic_with_hook::hbdbceb5cd158bf19@http://127.0.0.1:3000/index-3c6d44c9390fc4f2_bg.wasm:wasm-function[1843]:0xfd0a2
std::panicking::begin_panic_handler::{{closure}}::h9995bb2f0de4bb38@http://127.0.0.1:3000/index-3c6d44c9390fc4f2_bg.wasm:wasm-function[2837]:0x1275b0
std::sys_common::backtrace::__rust_end_short_backtrace::hc7608161a467c002@http://127.0.0.1:3000/index-3c6d44c9390fc4f2_bg.wasm:wasm-function[8331]:0x197971
rust_begin_unwind@http://127.0.0.1:3000/index-3c6d44c9390fc4f2_bg.wasm:wasm-function[7505]:0x18cfe2
core::panicking::panic_fmt::h3ab5417155b7ba3b@http://127.0.0.1:3000/index-3c6d44c9390fc4f2_bg.wasm:wasm-function[8332]:0x1979a7
core::result::unwrap_failed::h9bf99bca88ba05dc@http://127.0.0.1:3000/index-3c6d44c9390fc4f2_bg.wasm:wasm-function[3361]:0x138737
core::result::Result::unwrap::h33bc93175c1bc582@http://127.0.0.1:3000/index-3c6d44c9390fc4f2_bg.wasm:wasm-function[2644]:0x1205a8
surf::client::Client::url::h39313a8f3aaa19cf@http://127.0.0.1:3000/index-3c6d44c9390fc4f2_bg.wasm:wasm-function[1191]:0xd4d83
surf::client::Client::get::ha967bf82289d17fc@http://127.0.0.1:3000/index-3c6d44c9390fc4f2_bg.wasm:wasm-function[1862]:0xfe06a
ajars_surf::AjarsSurf::request::h6ae85bb0d856083f@http://127.0.0.1:3000/index-3c6d44c9390fc4f2_bg.wasm:wasm-function[298]:0x6b5f8
::update::{{closure}}::h6bffacbfd91ec472@http://127.0.0.1:3000/index-3c6d44c9390fc4f2_bg.wasm:wasm-function[258]:0x61af7
as core::future::future::Future>::poll::h402db801b284075c@http://127.0.0.1:3000/index-3c6d44c9390fc4f2_bg.wasm:wasm-function[695]:0xa8637
as yewtil::future::LinkFuture>::send_future::{{closure}}::ha636b22ecbda53c1@http://127.0.0.1:3000/index-3c6d44c9390fc4f2_bg.wasm:wasm-function[323]:0x70b63
as core::future::future::Future>::poll::hf132d4cc883e3691@http://127.0.0.1:3000/index-3c6d44c9390fc4f2_bg.wasm:wasm-function[2139]:0x10b6e4
wasm_bindgen_futures::task::singlethread::Task::run::h7fe7783a8d04cc40@http://127.0.0.1:3000/index-3c6d44c9390fc4f2_bg.wasm:wasm-function[555]:0x9738b
wasm_bindgen_futures::queue::QueueState::run_all::h0079a01c6732e655@http://127.0.0.1:3000/index-3c6d44c9390fc4f2_bg.wasm:wasm-function[706]:0xa9b02
wasm_bindgen_futures::queue::Queue::new::{{closure}}::h450bfa8f161ec151@http://127.0.0.1:3000/index-3c6d44c9390fc4f2_bg.wasm:wasm-function[4272]:0x15119c
+Output = R as wasm_bindgen::closure::WasmClosure>::describe::invoke::he5c7b3ad9ac2248f@http://127.0.0.1:3000/index-3c6d44c9390fc4f2_bg.wasm:wasm-function[1858]:0xfdd73
__wbg_adapter_27@http://127.0.0.1:3000/index-3c6d44c9390fc4f2.js:222:10
real@http://127.0.0.1:3000/index-3c6d44c9390fc4f2.js:191:20
```

I am also surprised that it panics instead of returning an error.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in surf/src/client.rs around the panic at line 548 and reproduce the relative-URL request in a browser-based WASM example. Trace how Client::url and Client::get handle URL parsing, then identify the existing tests covering URL errors. Done means relative URLs work as requested and invalid URL handling returns an error instead of panicking.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.