Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
363 changes: 358 additions & 5 deletions Cargo.lock

Large diffs are not rendered by default.

63 changes: 55 additions & 8 deletions crates/proxy_v2_models/src/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,34 +223,81 @@ pub fn detect_data_type(headers: &HeaderMap, body: &Bytes) -> DataType {

// ๋ฐ”์ด๋„ˆ๋ฆฌ ํŒŒ์ผ ๋‚ด์šฉ ๋ถ„์„ (์ด๋ฏธ์ง€, ๋™์˜์ƒ, ์˜ค๋””์˜ค, ๋ฌธ์„œ, ์•„์นด์ด๋ธŒ๋งŒ)

// ์ด๋ฏธ์ง€ ํŒŒ์ผ ๊ฐ์ง€ (๊ตฌ์ฒด์ ์ธ ํ˜•์‹)
// ์ด๋ฏธ์ง€ ํŒŒ์ผ ๊ฐ์ง€ (๊ตฌ์ฒด์ ์ธ ํ˜•์‹) - ์šฐ์„ ์ˆœ์œ„ ๋†’์Œ
// TODO @ohah: Improve image file detection logic
if body.len() >= 2 {
// PNG ์‹œ๊ทธ๋‹ˆ์ฒ˜
// PNG ์‹œ๊ทธ๋‹ˆ์ฒ˜ (๋งค์šฐ ๋ช…ํ™•)
if body.len() >= 8 && &body[0..8] == b"\x89PNG\r\n\x1a\n" {
return DataType::Image;
}
// JPEG ์‹œ๊ทธ๋‹ˆ์ฒ˜

// JPEG ์‹œ๊ทธ๋‹ˆ์ฒ˜ (๋งค์šฐ ๋ช…ํ™•)
if &body[0..2] == b"\xff\xd8" {
return DataType::Image;
}
// GIF ์‹œ๊ทธ๋‹ˆ์ฒ˜

// GIF ์‹œ๊ทธ๋‹ˆ์ฒ˜ (๋งค์šฐ ๋ช…ํ™•)
if body.len() >= 6 && (&body[0..6] == b"GIF87a" || &body[0..6] == b"GIF89a") {
return DataType::Image;
}
// WebP ์‹œ๊ทธ๋‹ˆ์ฒ˜

// WebP ์‹œ๊ทธ๋‹ˆ์ฒ˜ (RIFF ์ปจํ…Œ์ด๋„ˆ ํ™•์ธ)
if body.len() >= 12 && &body[0..4] == b"RIFF" && &body[8..12] == b"WEBP" {
return DataType::Image;
}

// BMP ์‹œ๊ทธ๋‹ˆ์ฒ˜
if body.len() >= 2 && &body[0..2] == b"BM" {
return DataType::Image;
}

// ICO ์‹œ๊ทธ๋‹ˆ์ฒ˜
if body.len() >= 4 && &body[0..4] == b"\x00\x00\x01\x00" {
return DataType::Image;
}

// TIFF ์‹œ๊ทธ๋‹ˆ์ฒ˜ (Little Endian)
if body.len() >= 4 && &body[0..4] == b"II*\x00" {
return DataType::Image;
}

// TIFF ์‹œ๊ทธ๋‹ˆ์ฒ˜ (Big Endian)
if body.len() >= 4 && &body[0..4] == b"MM\x00*" {
return DataType::Image;
}
}

// ๋น„๋””์˜ค ํŒŒ์ผ ๊ฐ์ง€ (ํ†ตํ•ฉ)
// TODO @ohah: Improve video file detection logic
if body.len() >= 4 {
// MP4 ์‹œ๊ทธ๋‹ˆ์ฒ˜
if body.len() >= 8 && (&body[4..8] == b"ftyp" || &body[4..8] == b"moov") {
if body.len() >= 8 {
// MP4 ์‹œ๊ทธ๋‹ˆ์ฒ˜ - ๋” ์ •ํ™•ํ•œ ๊ฐ์ง€
// MP4 ํŒŒ์ผ์€ 4๋ฐ”์ดํŠธ ํฌ๊ธฐ + "ftyp" + ๋ธŒ๋žœ๋“œ ์‹๋ณ„์ž๋กœ ์‹œ์ž‘
if &body[4..8] == b"ftyp" {
// MP4 ๋ธŒ๋žœ๋“œ ์‹๋ณ„์ž ํ™•์ธ (8-12๋ฒˆ์งธ ๋ฐ”์ดํŠธ)
if body.len() >= 12 {
let brand = &body[8..12];
// ์ผ๋ฐ˜์ ์ธ MP4 ๋ธŒ๋žœ๋“œ๋“ค
if brand == b"mp41"
|| brand == b"mp42"
|| brand == b"isom"
|| brand == b"avc1"
|| brand == b"iso2"
|| brand == b"iso3"
|| brand == b"iso4"
|| brand == b"iso5"
|| brand == b"iso6"
{
return DataType::Video;
}
}
}
// MOV ํŒŒ์ผ ์‹œ๊ทธ๋‹ˆ์ฒ˜ (QuickTime)
if &body[4..8] == b"moov" || &body[4..8] == b"mdat" {
return DataType::Video;
}
}

if body.len() >= 4 {
// WebM ์‹œ๊ทธ๋‹ˆ์ฒ˜
if &body[0..4] == b"\x1a\x45\xdf\xa3" {
return DataType::Video;
Expand Down
Loading