nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: algesten/ureq
Pull request #274 (2020-12-06 04:09:25)

[1.x] Fix broken behavior for 308 redirects
Previously, this would unconditionally panic:

```
thread '<unnamed>' panicked at 'attempt to subtract with overflow', /home/joshua/src/rust/ureq/src/unit.rs:244:59
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```

Follow-up to #253. Sorry for not testing earlier!

jsha: Thanks for the fix! Can you add a unittest that would detect the bug?
jsha: By the way, for the `main` branch, #275 refactors the redirect-counting code and happens to fix this.
jyn514: Done, I made sure it failed on master.

Patch:
diff --git a/src/unit.rs b/src/unit.rs
index bdeb077..ea349b3 100644
--- a/src/unit.rs
+++ b/src/unit.rs
@@ -240,8 +240,10 @@ pub(crate) fn connect(
                 // NOTE: DELETE is intentionally excluded: https://stackoverflow.com/questions/299628
                 307 | 308 if ["GET", "HEAD", "OPTIONS", "TRACE"].contains(&method.as_str()) => {
                     let empty = Payload::Empty.into_read();
+                    // recreate the unit to get a new hostname and cookies for the new host.
+                    let new_unit = Unit::new(req, &new_url, false, &empty);
                     debug!("redirect {} {} -> {}", resp.status(), url, new_url);
-                    return connect(req, unit, use_pooled, redirect_count - 1, empty, true);
+                    return connect(req, new_unit, use_pooled, redirect_count + 1, empty, true);
                 }
                 _ => (),
             };


Test patch:
diff --git a/src/test/redirect.rs b/src/test/redirect.rs
index 5ec1a41..23e1c5e 100644
--- a/src/test/redirect.rs
+++ b/src/test/redirect.rs
@@ -116,3 +116,17 @@ fn redirect_post() {
     assert!(resp.has("x-foo"));
     assert_eq!(resp.header("x-foo").unwrap(), "bar");
 }
+
+#[test]
+fn redirect_308() {
+    test::set_handler("/redirect_get3", |_| {
+        test::make_response(308, "Go here", vec!["Location: /valid_response"], vec![])
+    });
+    test::set_handler("/valid_response", |unit| {
+        assert_eq!(unit.req.method, "GET");
+        test::make_response(200, "OK", vec![], vec![])
+    });
+    let resp = get("test://host/redirect_get3").call();
+    assert_eq!(resp.status(), 200);
+    assert_eq!(resp.get_url(), "test://host/valid_response");
+}
Repository: alexcrichton/futures-rs
Pull request #583 (2017-09-18 19:55:58)

add is_canceled to unsync Sender
This method exists on the `sync` oneshot, but was missing from `unsync`.


Patch:
diff --git a/src/unsync/oneshot.rs b/src/unsync/oneshot.rs
index 4cedb98b..c895e68a 100644
--- a/src/unsync/oneshot.rs
+++ b/src/unsync/oneshot.rs
@@ -116,6 +116,23 @@ impl<T> Sender<T> {
             None => Ok(().into()),
         }
     }
+
+    /// Tests to see whether this `Sender`'s corresponding `Receiver`
+    /// has gone away.
+    ///
+    /// This function can be used to learn about when the `Receiver` (consumer)
+    /// half has gone away and nothing will be able to receive a message sent
+    /// from `send`.
+    ///
+    /// Note that this function is intended to *not* be used in the context of a
+    /// future. If you're implementing a future you probably want to call the
+    /// `poll_cancel` function which will block the current task if the
+    /// cancellation hasn't happened yet. This can be useful when working on a
+    /// non-futures related thread, though, which would otherwise panic if
+    /// `poll_cancel` were called.
+    pub fn is_canceled(&self) -> bool {
+        !self.inner.upgrade().is_some()
+    }
 }
 
 impl<T> Drop for Sender<T> {


Test patch:
diff --git a/tests/unsync-oneshot.rs b/tests/unsync-oneshot.rs
index 76d752e6..7f19d830 100644
--- a/tests/unsync-oneshot.rs
+++ b/tests/unsync-oneshot.rs
@@ -44,3 +44,12 @@ fn tx_dropped_rx_unparked() {
     }));
     assert_eq!(res.wait().unwrap_err(), Canceled);
 }
+
+
+#[test]
+fn is_canceled() {
+    let (tx, rx) = channel::<u32>();
+    assert!(!tx.is_canceled());
+    drop(rx);
+    assert!(tx.is_canceled());
+}