feat: 코드포스 JCEF 통과 쿠키 재사용으로 가져오기 가속 (#21)#22
Merged
Conversation
JCEF 폴백이 Cloudflare 챌린지를 통과하면 cf_clearance 쿠키가 JCEF 전역 쿠키 저장소에 남는다. 이후 Jsoup 요청에 이 쿠키를 실어 보내 챌린지 없이 빠른 경로로 통과 — 차단 환경에서도 첫 문제만 느리고(5~10초) 다음 문제부터 ~1초에 가져온다. - CodeforcesJcefFetcher.getCloudflareCookies(): 전역 쿠키 저장소에서 codeforces.com 쿠키 추출. CEF 미기동 시 빈 값 (쿠키를 읽으려고 CEF를 기동하지 않음) - CodeforcesCrawler.fetchProblem(): JCEF 쿠키를 로그인 쿠키와 병합해 전송 (같은 이름이면 로그인 쿠키 우선) - 쿠키가 만료·거부되면 403 → 기존 JCEF 폴백이 다시 돌며 새 쿠키가 저장되는 자가 회복 구조 - 쿠키 병합·ID 파싱 단위 테스트 추가
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #21
문제
Cloudflare가 차단하는 환경에서는 코드포스 문제를 가져올 때마다 느린 JCEF 폴백(5~60초: 브라우저 기동 + 챌린지 통과 대기)을 탐.
변경
JCEF가 챌린지를 통과하면
cf_clearance쿠키가 JCEF 전역 쿠키 저장소에 남는다는 점을 이용:CodeforcesJcefFetcher.getCloudflareCookies()— 전역 쿠키 저장소에서 codeforces.com 쿠키를 추출. CEF가 아직 시작되지 않았으면 빈 값 반환 (쿠키를 읽으려고 CEF를 기동하지 않음)CodeforcesCrawler.fetchProblem()— 추출한 쿠키를 로그인 쿠키와 병합해 Cookie 헤더로 전송. 같은 이름이면 로그인 쿠키 우선. UA는 기존의 Chrome UA 유지(cf_clearance의 UA 바인딩 대응, #8에서 도입)결과: 차단 환경에서도 첫 문제만 느리고, 이후 문제는 Jsoup 빠른 경로(~1초)로 통과.
자가 회복
쿠키가 만료되거나 거부되면 Jsoup이 다시 403 → 기존 JCEF 폴백이 실행되며 새 쿠키가 전역 저장소에 갱신됨. 별도 만료 관리가 필요 없음.
테스트
./gradlew compileKotlin test통과