Skip to content

Commit 6912b7f

Browse files
authored
Merge pull request #45 from rubytogether/segiddins/gracefully-handle-304s-in-clickhouse-stream
Gracefully handle 304s in clickhouse stream
2 parents 7ac2a9e + 826c12f commit 6912b7f

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/lib.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,28 @@ where
276276
let (name_len, version_len) =
277277
context.full_name_lengths.get(full_name).map_or_else(
278278
|| {
279-
Err(Error::new(
280-
ErrorKind::InvalidData,
281-
format!("unknown full name: {full_name:?} in {:?}", clickhouse),
282-
))
279+
if clickhouse.response_status.not_modified() {
280+
Ok(&(0, 0))
281+
} else {
282+
Err(Error::new(
283+
ErrorKind::InvalidData,
284+
format!(
285+
"unknown full name: {full_name:?} in {:?}",
286+
clickhouse
287+
),
288+
))
289+
}
283290
},
284291
Ok,
285292
)?;
293+
294+
// 304s can be missing the headers for gem, version, platform
295+
// Don't error if that's the case, just continue, since it is such
296+
// a small percentage of the requests.
297+
if *name_len == 0 && *version_len == 0 {
298+
continue;
299+
}
300+
286301
let name_end = *name_len as usize;
287302
let version_end = name_end + 1 + *version_len as usize;
288303
clickhouse.gem = Some(Cow::Borrowed(&full_name[..name_end]));

src/request.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ impl ResponseStatus {
1515
pub fn is_success(&self) -> bool {
1616
self.0 == 200 || self.0 == 304
1717
}
18+
19+
pub fn not_modified(&self) -> bool {
20+
self.0 == 304
21+
}
1822
}
1923

2024
impl<'de> Deserialize<'de> for ResponseStatus {

0 commit comments

Comments
 (0)