Skip to content

Commit 5089f37

Browse files
Remove mut to all getopt functions (#507)
* Use CURLOPT_TIMEOUT if timeout too big If the time that was converted into millisecond is more than the capacity of c_long, it will overflow, thus we need to convert it into seconds and use CURLOPT_TIMEOUT. * Remove mut to all getopt functions There is no mutation involve when calling getopt functions.
1 parent 746d702 commit 5089f37

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

src/easy/handler.rs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2727,7 +2727,7 @@ impl<H> Easy2<H> {
27272727
// /// Fetches this handle's private pointer-sized piece of data.
27282728
// ///
27292729
// /// This corresponds to `CURLINFO_PRIVATE` and defaults to 0.
2730-
// pub fn private(&mut self) -> Result<usize, Error> {
2730+
// pub fn private(&self) -> Result<usize, Error> {
27312731
// self.getopt_ptr(curl_sys::CURLINFO_PRIVATE).map(|p| p as usize)
27322732
// }
27332733

@@ -2767,7 +2767,7 @@ impl<H> Easy2<H> {
27672767
///
27682768
//// This corresponds to `CURLINFO_CONDITION_UNMET` and may return an error if the
27692769
/// option is not supported
2770-
pub fn time_condition_unmet(&mut self) -> Result<bool, Error> {
2770+
pub fn time_condition_unmet(&self) -> Result<bool, Error> {
27712771
self.getopt_long(curl_sys::CURLINFO_CONDITION_UNMET)
27722772
.map(|r| r != 0)
27732773
}
@@ -2781,7 +2781,7 @@ impl<H> Easy2<H> {
27812781
///
27822782
/// Returns `Ok(None)` if no effective url is listed or `Err` if an error
27832783
/// happens or the underlying bytes aren't valid utf-8.
2784-
pub fn effective_url(&mut self) -> Result<Option<&str>, Error> {
2784+
pub fn effective_url(&self) -> Result<Option<&str>, Error> {
27852785
self.getopt_str(curl_sys::CURLINFO_EFFECTIVE_URL)
27862786
}
27872787

@@ -2794,7 +2794,7 @@ impl<H> Easy2<H> {
27942794
///
27952795
/// Returns `Ok(None)` if no effective url is listed or `Err` if an error
27962796
/// happens or the underlying bytes aren't valid utf-8.
2797-
pub fn effective_url_bytes(&mut self) -> Result<Option<&[u8]>, Error> {
2797+
pub fn effective_url_bytes(&self) -> Result<Option<&[u8]>, Error> {
27982798
self.getopt_bytes(curl_sys::CURLINFO_EFFECTIVE_URL)
27992799
}
28002800

@@ -2806,7 +2806,7 @@ impl<H> Easy2<H> {
28062806
///
28072807
/// Corresponds to `CURLINFO_RESPONSE_CODE` and returns an error if this
28082808
/// option is not supported.
2809-
pub fn response_code(&mut self) -> Result<u32, Error> {
2809+
pub fn response_code(&self) -> Result<u32, Error> {
28102810
self.getopt_long(curl_sys::CURLINFO_RESPONSE_CODE)
28112811
.map(|c| c as u32)
28122812
}
@@ -2818,7 +2818,7 @@ impl<H> Easy2<H> {
28182818
///
28192819
/// Corresponds to `CURLINFO_HTTP_CONNECTCODE` and returns an error if this
28202820
/// option is not supported.
2821-
pub fn http_connectcode(&mut self) -> Result<u32, Error> {
2821+
pub fn http_connectcode(&self) -> Result<u32, Error> {
28222822
self.getopt_long(curl_sys::CURLINFO_HTTP_CONNECTCODE)
28232823
.map(|c| c as u32)
28242824
}
@@ -2837,7 +2837,7 @@ impl<H> Easy2<H> {
28372837
///
28382838
/// This corresponds to `CURLINFO_FILETIME` and may return an error if the
28392839
/// option is not supported
2840-
pub fn filetime(&mut self) -> Result<Option<i64>, Error> {
2840+
pub fn filetime(&self) -> Result<Option<i64>, Error> {
28412841
self.getopt_long(curl_sys::CURLINFO_FILETIME).map(|r| {
28422842
if r == -1 {
28432843
None
@@ -2856,7 +2856,7 @@ impl<H> Easy2<H> {
28562856
///
28572857
/// This corresponds to `CURLINFO_SIZE_DOWNLOAD` and may return an error if the
28582858
/// option is not supported
2859-
pub fn download_size(&mut self) -> Result<f64, Error> {
2859+
pub fn download_size(&self) -> Result<f64, Error> {
28602860
self.getopt_double(curl_sys::CURLINFO_SIZE_DOWNLOAD)
28612861
.map(|r| r as f64)
28622862
}
@@ -2867,7 +2867,7 @@ impl<H> Easy2<H> {
28672867
///
28682868
/// This corresponds to `CURLINFO_SIZE_UPLOAD` and may return an error if the
28692869
/// option is not supported
2870-
pub fn upload_size(&mut self) -> Result<f64, Error> {
2870+
pub fn upload_size(&self) -> Result<f64, Error> {
28712871
self.getopt_double(curl_sys::CURLINFO_SIZE_UPLOAD)
28722872
.map(|r| r as f64)
28732873
}
@@ -2879,7 +2879,7 @@ impl<H> Easy2<H> {
28792879
///
28802880
/// This corresponds to `CURLINFO_CONTENT_LENGTH_DOWNLOAD` and may return an error if the
28812881
/// option is not supported
2882-
pub fn content_length_download(&mut self) -> Result<f64, Error> {
2882+
pub fn content_length_download(&self) -> Result<f64, Error> {
28832883
self.getopt_double(curl_sys::CURLINFO_CONTENT_LENGTH_DOWNLOAD)
28842884
.map(|r| r as f64)
28852885
}
@@ -2891,7 +2891,7 @@ impl<H> Easy2<H> {
28912891
///
28922892
/// Corresponds to `CURLINFO_TOTAL_TIME` and may return an error if the
28932893
/// option isn't supported.
2894-
pub fn total_time(&mut self) -> Result<Duration, Error> {
2894+
pub fn total_time(&self) -> Result<Duration, Error> {
28952895
self.getopt_double(curl_sys::CURLINFO_TOTAL_TIME)
28962896
.map(double_seconds_to_duration)
28972897
}
@@ -2903,7 +2903,7 @@ impl<H> Easy2<H> {
29032903
///
29042904
/// Corresponds to `CURLINFO_NAMELOOKUP_TIME` and may return an error if the
29052905
/// option isn't supported.
2906-
pub fn namelookup_time(&mut self) -> Result<Duration, Error> {
2906+
pub fn namelookup_time(&self) -> Result<Duration, Error> {
29072907
self.getopt_double(curl_sys::CURLINFO_NAMELOOKUP_TIME)
29082908
.map(double_seconds_to_duration)
29092909
}
@@ -2915,7 +2915,7 @@ impl<H> Easy2<H> {
29152915
///
29162916
/// Corresponds to `CURLINFO_CONNECT_TIME` and may return an error if the
29172917
/// option isn't supported.
2918-
pub fn connect_time(&mut self) -> Result<Duration, Error> {
2918+
pub fn connect_time(&self) -> Result<Duration, Error> {
29192919
self.getopt_double(curl_sys::CURLINFO_CONNECT_TIME)
29202920
.map(double_seconds_to_duration)
29212921
}
@@ -2930,7 +2930,7 @@ impl<H> Easy2<H> {
29302930
///
29312931
/// Corresponds to `CURLINFO_APPCONNECT_TIME` and may return an error if the
29322932
/// option isn't supported.
2933-
pub fn appconnect_time(&mut self) -> Result<Duration, Error> {
2933+
pub fn appconnect_time(&self) -> Result<Duration, Error> {
29342934
self.getopt_double(curl_sys::CURLINFO_APPCONNECT_TIME)
29352935
.map(double_seconds_to_duration)
29362936
}
@@ -2945,7 +2945,7 @@ impl<H> Easy2<H> {
29452945
///
29462946
/// Corresponds to `CURLINFO_PRETRANSFER_TIME` and may return an error if the
29472947
/// option isn't supported.
2948-
pub fn pretransfer_time(&mut self) -> Result<Duration, Error> {
2948+
pub fn pretransfer_time(&self) -> Result<Duration, Error> {
29492949
self.getopt_double(curl_sys::CURLINFO_PRETRANSFER_TIME)
29502950
.map(double_seconds_to_duration)
29512951
}
@@ -2958,7 +2958,7 @@ impl<H> Easy2<H> {
29582958
///
29592959
/// Corresponds to `CURLINFO_STARTTRANSFER_TIME` and may return an error if the
29602960
/// option isn't supported.
2961-
pub fn starttransfer_time(&mut self) -> Result<Duration, Error> {
2961+
pub fn starttransfer_time(&self) -> Result<Duration, Error> {
29622962
self.getopt_double(curl_sys::CURLINFO_STARTTRANSFER_TIME)
29632963
.map(double_seconds_to_duration)
29642964
}
@@ -2972,7 +2972,7 @@ impl<H> Easy2<H> {
29722972
///
29732973
/// Corresponds to `CURLINFO_REDIRECT_TIME` and may return an error if the
29742974
/// option isn't supported.
2975-
pub fn redirect_time(&mut self) -> Result<Duration, Error> {
2975+
pub fn redirect_time(&self) -> Result<Duration, Error> {
29762976
self.getopt_double(curl_sys::CURLINFO_REDIRECT_TIME)
29772977
.map(double_seconds_to_duration)
29782978
}
@@ -2981,7 +2981,7 @@ impl<H> Easy2<H> {
29812981
///
29822982
/// Corresponds to `CURLINFO_REDIRECT_COUNT` and may return an error if the
29832983
/// option isn't supported.
2984-
pub fn redirect_count(&mut self) -> Result<u32, Error> {
2984+
pub fn redirect_count(&self) -> Result<u32, Error> {
29852985
self.getopt_long(curl_sys::CURLINFO_REDIRECT_COUNT)
29862986
.map(|c| c as u32)
29872987
}
@@ -2996,7 +2996,7 @@ impl<H> Easy2<H> {
29962996
///
29972997
/// Corresponds to `CURLINFO_REDIRECT_URL` and may return an error if the
29982998
/// url isn't valid utf-8 or an error happens.
2999-
pub fn redirect_url(&mut self) -> Result<Option<&str>, Error> {
2999+
pub fn redirect_url(&self) -> Result<Option<&str>, Error> {
30003000
self.getopt_str(curl_sys::CURLINFO_REDIRECT_URL)
30013001
}
30023002

@@ -3009,15 +3009,15 @@ impl<H> Easy2<H> {
30093009
/// URL.
30103010
///
30113011
/// Corresponds to `CURLINFO_REDIRECT_URL` and may return an error.
3012-
pub fn redirect_url_bytes(&mut self) -> Result<Option<&[u8]>, Error> {
3012+
pub fn redirect_url_bytes(&self) -> Result<Option<&[u8]>, Error> {
30133013
self.getopt_bytes(curl_sys::CURLINFO_REDIRECT_URL)
30143014
}
30153015

30163016
/// Get size of retrieved headers
30173017
///
30183018
/// Corresponds to `CURLINFO_HEADER_SIZE` and may return an error if the
30193019
/// option isn't supported.
3020-
pub fn header_size(&mut self) -> Result<u64, Error> {
3020+
pub fn header_size(&self) -> Result<u64, Error> {
30213021
self.getopt_long(curl_sys::CURLINFO_HEADER_SIZE)
30223022
.map(|c| c as u64)
30233023
}
@@ -3026,7 +3026,7 @@ impl<H> Easy2<H> {
30263026
///
30273027
/// Corresponds to `CURLINFO_REQUEST_SIZE` and may return an error if the
30283028
/// option isn't supported.
3029-
pub fn request_size(&mut self) -> Result<u64, Error> {
3029+
pub fn request_size(&self) -> Result<u64, Error> {
30303030
self.getopt_long(curl_sys::CURLINFO_REQUEST_SIZE)
30313031
.map(|c| c as u64)
30323032
}
@@ -3040,7 +3040,7 @@ impl<H> Easy2<H> {
30403040
///
30413041
/// Corresponds to `CURLINFO_CONTENT_TYPE` and may return an error if the
30423042
/// option isn't supported.
3043-
pub fn content_type(&mut self) -> Result<Option<&str>, Error> {
3043+
pub fn content_type(&self) -> Result<Option<&str>, Error> {
30443044
self.getopt_str(curl_sys::CURLINFO_CONTENT_TYPE)
30453045
}
30463046

@@ -3053,7 +3053,7 @@ impl<H> Easy2<H> {
30533053
///
30543054
/// Corresponds to `CURLINFO_CONTENT_TYPE` and may return an error if the
30553055
/// option isn't supported.
3056-
pub fn content_type_bytes(&mut self) -> Result<Option<&[u8]>, Error> {
3056+
pub fn content_type_bytes(&self) -> Result<Option<&[u8]>, Error> {
30573057
self.getopt_bytes(curl_sys::CURLINFO_CONTENT_TYPE)
30583058
}
30593059

@@ -3064,7 +3064,7 @@ impl<H> Easy2<H> {
30643064
///
30653065
/// Corresponds to `CURLINFO_OS_ERRNO` and may return an error if the
30663066
/// option isn't supported.
3067-
pub fn os_errno(&mut self) -> Result<i32, Error> {
3067+
pub fn os_errno(&self) -> Result<i32, Error> {
30683068
self.getopt_long(curl_sys::CURLINFO_OS_ERRNO)
30693069
.map(|c| c as i32)
30703070
}
@@ -3077,15 +3077,15 @@ impl<H> Easy2<H> {
30773077
///
30783078
/// Corresponds to `CURLINFO_PRIMARY_IP` and may return an error if the
30793079
/// option isn't supported.
3080-
pub fn primary_ip(&mut self) -> Result<Option<&str>, Error> {
3080+
pub fn primary_ip(&self) -> Result<Option<&str>, Error> {
30813081
self.getopt_str(curl_sys::CURLINFO_PRIMARY_IP)
30823082
}
30833083

30843084
/// Get the latest destination port number
30853085
///
30863086
/// Corresponds to `CURLINFO_PRIMARY_PORT` and may return an error if the
30873087
/// option isn't supported.
3088-
pub fn primary_port(&mut self) -> Result<u16, Error> {
3088+
pub fn primary_port(&self) -> Result<u16, Error> {
30893089
self.getopt_long(curl_sys::CURLINFO_PRIMARY_PORT)
30903090
.map(|c| c as u16)
30913091
}
@@ -3098,15 +3098,15 @@ impl<H> Easy2<H> {
30983098
///
30993099
/// Corresponds to `CURLINFO_LOCAL_IP` and may return an error if the
31003100
/// option isn't supported.
3101-
pub fn local_ip(&mut self) -> Result<Option<&str>, Error> {
3101+
pub fn local_ip(&self) -> Result<Option<&str>, Error> {
31023102
self.getopt_str(curl_sys::CURLINFO_LOCAL_IP)
31033103
}
31043104

31053105
/// Get the latest local port number
31063106
///
31073107
/// Corresponds to `CURLINFO_LOCAL_PORT` and may return an error if the
31083108
/// option isn't supported.
3109-
pub fn local_port(&mut self) -> Result<u16, Error> {
3109+
pub fn local_port(&self) -> Result<u16, Error> {
31103110
self.getopt_long(curl_sys::CURLINFO_LOCAL_PORT)
31113111
.map(|c| c as u16)
31123112
}
@@ -3426,7 +3426,7 @@ impl<H> Easy2<H> {
34263426
unsafe { self.cvt(curl_sys::curl_easy_setopt(self.inner.handle, opt, blob_ptr)) }
34273427
}
34283428

3429-
fn getopt_bytes(&mut self, opt: curl_sys::CURLINFO) -> Result<Option<&[u8]>, Error> {
3429+
fn getopt_bytes(&self, opt: curl_sys::CURLINFO) -> Result<Option<&[u8]>, Error> {
34303430
unsafe {
34313431
let p = self.getopt_ptr(opt)?;
34323432
if p.is_null() {
@@ -3437,7 +3437,7 @@ impl<H> Easy2<H> {
34373437
}
34383438
}
34393439

3440-
fn getopt_ptr(&mut self, opt: curl_sys::CURLINFO) -> Result<*const c_char, Error> {
3440+
fn getopt_ptr(&self, opt: curl_sys::CURLINFO) -> Result<*const c_char, Error> {
34413441
unsafe {
34423442
let mut p = ptr::null();
34433443
let rc = curl_sys::curl_easy_getinfo(self.inner.handle, opt, &mut p);
@@ -3446,7 +3446,7 @@ impl<H> Easy2<H> {
34463446
}
34473447
}
34483448

3449-
fn getopt_str(&mut self, opt: curl_sys::CURLINFO) -> Result<Option<&str>, Error> {
3449+
fn getopt_str(&self, opt: curl_sys::CURLINFO) -> Result<Option<&str>, Error> {
34503450
match self.getopt_bytes(opt) {
34513451
Ok(None) => Ok(None),
34523452
Err(e) => Err(e),
@@ -3457,7 +3457,7 @@ impl<H> Easy2<H> {
34573457
}
34583458
}
34593459

3460-
fn getopt_long(&mut self, opt: curl_sys::CURLINFO) -> Result<c_long, Error> {
3460+
fn getopt_long(&self, opt: curl_sys::CURLINFO) -> Result<c_long, Error> {
34613461
unsafe {
34623462
let mut p = 0;
34633463
let rc = curl_sys::curl_easy_getinfo(self.inner.handle, opt, &mut p);
@@ -3466,7 +3466,7 @@ impl<H> Easy2<H> {
34663466
}
34673467
}
34683468

3469-
fn getopt_double(&mut self, opt: curl_sys::CURLINFO) -> Result<c_double, Error> {
3469+
fn getopt_double(&self, opt: curl_sys::CURLINFO) -> Result<c_double, Error> {
34703470
unsafe {
34713471
let mut p = 0 as c_double;
34723472
let rc = curl_sys::curl_easy_getinfo(self.inner.handle, opt, &mut p);

0 commit comments

Comments
 (0)