Skip to content

Conversation

@whqtker
Copy link
Member

@whqtker whqtker commented Nov 27, 2025

관련 이슈

작업 내용

모든 요청에 대해 Connection 헤더의 값이 upgrade로 설정되는 문제가 있었습니다.
Upgrade 헤더 유무에 따라 Connection 헤더의 값을 동적으로 설정하도록 수정하였습니다.

특이 사항

AS-IS

WebSocket 핸드셰이크

  • 클라이언트는 Nginx에 Connection 헤더에 Upgrade, Upgrade 헤더에 websocket 을 포함하여 전송한다.
  • Nginx는 이를 수신 후, Connection 헤더의 값을 Upgrade, Upgrade 헤더에 받은 요청의 Upgrade 헤더 값으로 설정하여 서버로 전송한다.
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
  • 아래는 실제 Nginx로부터 받은 요청입니다.
  • 수정: IP 주소와 같은 민감 정보는 지웠습니다.
GET /connect/123/randomsession/websocket?token=YOUR_ACCESS_TOKEN HTTP/1.1
Host: api.stage.solid-connection.com
X-Real-IP: XXX.XX.XXX.XX
X-Forwarded-For: XXX.XX.XXX.XX
X-Forwarded-Proto: https
Upgrade: websocket
Connection: upgrade
User-Agent: curl/7.81.0
Accept: */*
Sec-WebSocket-Version: 13
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==

일반 HTTP 요청

  • 클라이언트는 Nginx에 Connection 헤더에 keep-alive, Upgrade 헤더는 값을 포함하지 않은 채 전송한다.
  • Nginx는 이를 수신 후, Connection 헤더의 값을 Upgrade로 설정하고, Upgrade 헤더의 값을 null로 설정하여 서버로 전송한다.
  • 요청을 받은 서버는 Upgrade 요청이나 정작 Upgrade 헤더의 값이 비어있는 것을 보고 일반 HTTP로 처리한다.
  • 아래는 실제 Nginx로부터 받은 요청입니다.
GET / HTTP/1.1
Host: api.stage.solid-connection.com
X-Real-IP: 1XXX.XX.XXX.XX
X-Forwarded-For: XXX.XX.XXX.XX
X-Forwarded-Proto: https
Connection: upgrade
User-Agent: curl/7.81.0
Accept: */*

리뷰 요구사항 (선택)

- Upgrade 헤더가 존재하면(e.g. WebSocket) upgrade로 설정
- Upgrade 헤더가 존재하지 않으면 keep-alive로 설정
@coderabbitai
Copy link

coderabbitai bot commented Nov 27, 2025

Walkthrough

Nginx 설정 파일 두 개(개발 및 프로덕션 환경)에 동적 연결 업그레이드 처리를 추가했습니다.

  1. Map 블록 추가 — 각 설정 파일에 $connection_upgrade 변수를 정의하는 맵 블록을 삽입했으며, 기본값은 upgrade로 설정하고 빈 문자열일 경우 keep-alive로 처리하도록 구성했습니다.

  2. 프록시 헤더 동적화 — HTTPS 서버 블록의 proxy_set_header Connection 지시어를 정적인 "upgrade" 문자열에서 동적인 $connection_upgrade 변수로 변경하여, HTTP 업그레이드 헤더 값에 따라 조건부로 연결을 처리하도록 개선했습니다.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10분

  • 일관된 패턴의 변경이 두 개 파일에 반복 적용됨
  • Map 블록 문법 검증 필요
  • 변수 바인딩의 정확성 확인 권장

Suggested reviewers

  • nayonsoso
  • wibaek
  • lsy1307

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목이 Upgrade 헤더 유무에 따라 Connection 헤더를 동적으로 설정한다는 변경사항의 핵심을 명확하게 설명하고 있습니다.
Linked Issues check ✅ Passed nginx.dev.conf와 nginx.prod.conf에 map 블록을 추가하여 Upgrade 헤더 유무에 따라 Connection 헤더를 조건부로 설정함으로써 #578의 요구사항을 충족합니다.
Out of Scope Changes check ✅ Passed 모든 변경사항이 #578 이슈에서 명시한 Nginx 설정 파일의 Connection 헤더 동적 설정이라는 범위 내에 있으며, 무관한 변경사항은 없습니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed PR 설명이 제공된 템플릿의 필수 섹션(관련 이슈, 작업 내용, 특이 사항)을 모두 포함하고 있으며, 특히 AS-IS 상황을 상세한 요청 예제와 함께 명확하게 설명하고 있습니다.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@sukangpunch sukangpunch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다! 제가 프로토콜에 대해 이해도가 낮아 간단하게 궁금한 내용이 있어서 여쭈어 봅니다.

만약 Connection 헤더가 upgrade 인 상황에선 어떤 문제가 발생하나요?
간단하게 알아 본 결과 요청 및 응답 결과에 대한 문제는 없지만,

  1. 프로토콜 표준 위반
  2. 리소스 비효율
    • 서버가 프로토콜 전환을 기대하며 대기 할 수 있다.(연결이 길어짐)
  3. 의미없는 리소스 점유
    • 실제로는 일반 http 요청인데 websocket 대기 상태처럼 처리

개선 내용

  1. 모든 요청에 Connection: upgrade로 가는 상황에서, Upgrade 헤더 기반으로 upgrade, keep-alive 의 값이 들어가게 함
    • 즉, websocket 연결이면 upgrade로 프로토콜을 변경하고, http 연결이면 Connection을 keep-alive로 유지하게 한다

이 정도의 문제로 이해하고 있는데 맞는지 궁금합니다!!

@whqtker
Copy link
Member Author

whqtker commented Nov 28, 2025

고생하셨습니다! 제가 프로토콜에 대해 이해도가 낮아 간단하게 궁금한 내용이 있어서 여쭈어 봅니다.

만약 Connection 헤더가 upgrade 인 상황에선 어떤 문제가 발생하나요? 간단하게 알아 본 결과 요청 및 응답 결과에 대한 문제는 없지만,

  1. 프로토콜 표준 위반

  2. 리소스 비효율

    • 서버가 프로토콜 전환을 기대하며 대기 할 수 있다.(연결이 길어짐)
  3. 의미없는 리소스 점유

    • 실제로는 일반 http 요청인데 websocket 대기 상태처럼 처리

서버가 Connection 헤더의 값이 upgrade로 설정되었으나 정작 Upgrade 헤더가 없는 응답을 받고, 따로 요청을 거절하지 않고 Upgrade 동작만 무시한 채 일반 HTTP 요청처럼 간주하는 것으로 알고 있습니다. 즉, 알아보신 바와 같이 동작에는 문제가 없습니다.
다만, 어쨌든 의도하지 않는 동작이므로 수정했습니다 !

개선 내용

  1. 모든 요청에 Connection: upgrade로 가는 상황에서, Upgrade 헤더 기반으로 upgrade, keep-alive 의 값이 들어가게 함

    • 즉, websocket 연결이면 upgrade로 프로토콜을 변경하고, http 연결이면 Connection을 keep-alive로 유지하게 한다

이 정도의 문제로 이해하고 있는데 맞는지 궁금합니다!!

이해하신 것이 맞습니다 🙆‍♂️

Copy link
Contributor

@sukangpunch sukangpunch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!

Copy link
Contributor

@Gyuhyeok99 Gyuhyeok99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오! 이런 건 또 처음알았네요! 공유해주셔서 감사합니다~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: HTTP 요청에 Connection 헤더가 upgrade로 설정되는 문제 해결

3 participants