CORS์ Preflight Request, Simple Request ์ ์ฐจ
CORS๋
๐ก โ๋ค๋ฅธ ์ถ์ฒโ์ ๋ฆฌ์์ค๋ฅผ ์์ฒญํ ๋ ์ง์ผ์ผ ํ๋ ์ ์ฑ
- ์ถ๊ฐ HTTP ํค๋๋ฅผ ์ฌ์ฉํ์ฌ, ํ ์ถ์ฒ์์ ์คํ ์ค์ธ ์น ์ ํ๋ฆฌ์ผ์ด์
์ด ๋ค๋ฅธ ์ถ์ฒ์ ์ ํํ ์์์ ์ ๊ทผํ ์ ์๋ ๊ถํ์ ๋ถ์ฌํ๋๋ก ๋ธ๋ผ์ฐ์ ์ ์๋ ค์ค
Preflight Request (์ฌ์ ์์ฒญ)
CORS Preflight Request๋ HTTP ์์ฒญ ์ ์ ์๋ฒ ์ธก์์ ๊ทธ ์์ฒญ์ ๋ฉ์๋์ ํค๋์ ๋ํด ์ธ์ํ๊ณ ์๋์ง ํ์ธํ๋ ์์ฒญ

์ถ์ฒ: https://velog.io/@wiostz98kr/CORS์-๋ชจ๋ -๊ฒ
- ์๋ฒ ์ํ๋ฅผ ๋ณ๊ฒฝํ ์ ์๋ ์์ฒญ ๋๋ ์ปค์คํ
ํค๋๋ฅผ ํฌํจํ๋ ์์ฒญ POST, PUT, PATCH, GET(with custom headers)
- OPTIONS ์์ฒญ ์ฃผ์ด์ง URL ๋๋ ์๋ฒ์ ๋ํด ํ์ฉ๋ ํต์ ์ต์
์ ์์ฒญ โ ํด๋ผ์ด์ธํธ๋ URL์ ์ง์ ํ๊ฑฐ๋ *๋ฅผ ์ง์ ํ์ฌ ์ ์ฒด ์๋ฒ๋ฅผ ์ฐธ์กฐ
OPTIONS /resources/post-here/ HTTP/1.1
Host: bar.example
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Connection: keep-alive
Origin: https://foo.example
Access-Control-Request-Method: POST
Access-Control-Request-Headers: X-PINGOTHER, Content-Type
- ๋ธ๋ผ์ฐ์ ์์ ์๋์ผ๋ก ๋ฐ์ Simple Request์ ๊ฒฝ์ฐ Preflingt Regust๊ฐ ์๋ต
- ์์
- ํด๋ผ์ด์ธํธ๊ฐ DELETE ์์ฒญ์ ํ๊ธฐ ์ ์ Preflight Request๋ฅผ ํตํด ์๋ฒ๊ฐ DELETE๋ฅผ ํ์ฉํ๋์ง ํ์ธ
OPTIONS /resource/foo
Access-Control-Request-Method: DELETE
Access-Control-Request-Headers: origin, x-requested-with
Origin: https://foo.bar.org
- ์๋ฒ๊ฐ ํ์ฉํ๋ ๊ฒฝ์ฐ, Access-Control-Allow-Methods ํค๋ ๊ฐ์ DELETE๋ฅผ ํฌํจํ์ฌ ์๋ต
HTTP/1.1 204 No Content
Connection: keep-alive
Access-Control-Allow-Origin: https://foo.bar.org
Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE
Access-Control-Max-Age: 86400
Simple Request (๋จ์ ์์ฒญ)
CORS Preflight ์์ฒญ ์์ด ์ง์ ์ ์ก๋๋ ์์ฒญ
- GET, HEAD์ ๊ฐ์ด ์๋ฒ ์ํ๋ฅผ ์กฐํํ๋ ์์ฒญ, ์๋ฒ๋ ์๋ต๊ณผ ํจ๊ป CORS ํค๋๋ฅผ ๋ณด๋ด๊ณ , ๋ธ๋ผ์ฐ์ ๋ ํด๋น ํค๋๊ฐ ์์ฒญ๊ณผ ๋ถํฉํ์ง ์๋ ๊ฒฝ์ฐ ๊ฒฐ๊ณผ๋ฅผ ํ๊ธฐ
์ถ์ฒ: https://velog.io/@wiostz98kr/CORS์-๋ชจ๋ -๊ฒ
- ์๋์ ์กฐ๊ฑด์ ๋ชจ๋ ๋ง์กฑํด์ผํ Preflight Request ์๋ต ๊ฐ๋ฅ
- ์์ฒญ์ ๋ฉ์๋ GET, HEAD, POST ์ค ํ๋์ฌ์ผ ํจ
- Accept, Accept-Language, Content-Language, Content-Type, DPR, DOwnlink, Save-Data, Viewport-Width, Width๋ฅผ ์ ์ธํ ํค๋๋ฅผ ์ฌ์ฉํ๋ฉด ์๋จ
- Content-Type๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ์ application/x-www-form-urlencoded, multipart/form-data, text/plain๋ง ํ์ฉ (application/json ์ปจํ
์ธ ํ์
X)
