Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: default content-type #30

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

fix: default content-type #30

wants to merge 4 commits into from

Conversation

yougyung
Copy link
Member

@yougyung yougyung commented Jan 12, 2025

๐Ÿ“Œ ์ž‘์—… ๋‚ด์šฉ

๊ตฌํ˜„ ๋‚ด์šฉ ๋ฐ ์ž‘์—… ํ–ˆ๋˜ ๋‚ด์—ญ

  • fetch-ax์˜ header์˜ default value ์ œ๊ฑฐ
  • data๊ฐ€ JSON type์ธ ๊ฒฝ์šฐ, ์ž๋™์œผ๋กœ application/json์„ content-type์œผ๋กœ ์„ค์ •ํ•˜๋Š” ๋กœ์ง ์ถ”๊ฐ€
  • README์— ์กฐ๊ฑด๋ถ€๋กœ ๋ฐœ์ƒํ•˜๋Š” default value ๋ฐ˜์˜

๋ฌธ์ œ

  • fetch๋Š” content-type์„ ์ง€์ •ํ•˜์ง€ ์•Š๊ณ  formdata๋ฅผ body๋กœ ์„ค์ •ํ•˜๋Š” ๊ฒฝ์šฐ, ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ์ž๋™์œผ๋กœ content-type์„ ์„ค์ •ํ•ด์ฃผ๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. fetch-ax์˜ ๊ฒฝ์šฐ content-type์˜ ๊ธฐ๋ณธ๊ฐ’์ด application/json์œผ๋กœ ์„ค์ •๋˜์–ด ์žˆ์–ด ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

๐Ÿค” ๊ณ ๋ฏผ ํ–ˆ๋˜ ๋ถ€๋ถ„

fetch-ax๊ฐ€ content-type์˜ ๊ธฐ๋ณธ๊ฐ’์„ application/json์œผ๋กœ ์„ค์ •ํ•œ ๋ชฉ์ 

  • data๊ฐ€ jsonํ˜•์‹์ด ๊ฐ€์žฅ ๋งŽ์ด ์ „์†ก ๋  ๊ฒƒ์ด๋ผ๊ณ  ์˜ˆ์ƒํ–ˆ๊ธฐ ๋•Œ๋ฌธ
    -> fetch-ax๊ฐ€ content-type์˜ ๊ธฐ๋ณธ๊ฐ’์„ application/json์œผ๋กœ ์„ค์ •ํ•œ ๋ชฉ์ ์„ ์ถฉ์กฑ์‹œํ‚ค๊ธฐ ์œ„ํ•ด, data๊ฐ€ JSON type์ธ ๊ฒฝ์šฐ์— ์ž๋™์œผ๋กœ application/json์„ content-type์œผ๋กœ ์„ค์ •ํ•˜๋Š” ๋กœ์ง์„ ์ถ”๊ฐ€ํ•ด ์ด๋ฅผ ๋Œ€์‘

๋ณ€๊ฒฝ๋œ ๋กœ์ง

  • content-type์˜ ๊ธฐ๋ณธ๊ฐ’ ์ œ๊ฑฐ
  • data๊ฐ€ JSON type์ธ ๊ฒฝ์šฐ, ์ž๋™์œผ๋กœ application/json์„ content-type์œผ๋กœ ์„ค์ •

@yougyung yougyung linked an issue Jan 12, 2025 that may be closed by this pull request
Copy link
Member

@gahyuun gahyuun left a comment

Choose a reason for hiding this comment

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

fetch์—์„œ๋Š” ์•„๋ฌด๊ฒƒ๋„ ์ž…๋ ฅํ•˜์ง€์•Š์„๋•Œ ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ์•Œ์•„์„œ content-type์„ ๋„ฃ์–ด์ฃผ์ง€๋งŒ, fetch-ax๋Š” application/json์„ default๋กœ ๊ฐ–๊ณ  ์žˆ๊ธฐ์— ํ•ด๋‹น ๊ธฐ๋Šฅ๋“ค์„ ์ œ๊ณตํ•ด์ฃผ์ง€ ๋ชปํ•˜๋Š”๊ฒŒ ๋ฌธ์ œ์—ฌ์„œ ํ•ด๊ฒฐํ•œ๊ฒŒ ๋งž์„๊นŒ์š” ?? ๐Ÿค—
๋ฆฌ๋“œ๋ฏธ ์ˆ˜์ •๊นŒ์ง€,, ๊ณ ์ƒ ๋งŽ์œผ์…จ์Šต๋‹ˆ๋‹ค ~!


##### headers

- By default, there is no default value for headers. But it's content-type is `application/json` only if the data is `json`
Copy link
Member

Choose a reason for hiding this comment

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

data๊ฐ€ json์ธ ๊ฒฝ์šฐ์—๋Š” ์ €ํฌ๊ฐ€ application/json์œผ๋กœ "์„ค์ •"ํ•ด์ฃผ๋Š” ๊ฒƒ์ด๊ธฐ์—
is ๋Œ€์‹  is set to ์š”๋ก ์‹์œผ๋กœ ์ž‘์„ฑํ•˜๋ฉด ์–ด๋–จ๊นŒ์š” ~?

return (
isJson(data) || // data === 'string' ์„ ํ†ตํ•ด์„œ๋„ JSON์ธ์ง€๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์ง€๋งŒ ๋ช…์‹œ์ ์œผ๋กœ ๋”ฐ์ง€๊ธฐ ์œ„ํ•ด์„œ
typeof data === 'string' ||
data instanceof ReadableStream ||
(typeof ReadableStream !== 'undefined' && data instanceof ReadableStream) ||
Copy link
Member

@gahyuun gahyuun Jan 12, 2025

Choose a reason for hiding this comment

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

์ด ์ฝ”๋“œ๋Š” ์–ด๋–ค ์˜๋„๋กœ ์ถ”๊ฐ€๋œ๊ฑธ๊นŒ์š” !? ํ˜น์‹œ ์–ด๋–ค ์˜ค๋ฅ˜๋ฅผ ๋ฐœ๊ฒฌํ•˜์…จ๋‚˜์šฉ?

@@ -334,6 +341,16 @@ function isHttpError(response: Response) {
return response.status >= 300;
}

function appendJsonContentType(
Copy link
Member

Choose a reason for hiding this comment

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

์ €ํฌ rollup ์‚ฌ์šฉํ•œ ์ดํ›„๋กœ ํŒŒ์ผ ๋ถ„๋ฆฌ๋ฅผ ์•ˆํ–ˆ๋„ค์š”!! ์ด ๋ถ€๋ถ„ ์ œ๊ฐ€ ์ด์Šˆ์— ์ถ”๊ฐ€ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค

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 default content-type
2 participants