From 7aba1b2cf47e2d6769c19da6aa4260a1208f18d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=ED=98=84=EC=9A=B0?= Date: Sun, 31 May 2026 20:13:15 +0900 Subject: [PATCH 1/4] =?UTF-8?q?docs:=20post.view/server.js=20=EB=B2=88?= =?UTF-8?q?=EC=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 5-network/08-xmlhttprequest/post.view/server.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/5-network/08-xmlhttprequest/post.view/server.js b/5-network/08-xmlhttprequest/post.view/server.js index 50cfc5ae36..0e6d4fb6e4 100644 --- a/5-network/08-xmlhttprequest/post.view/server.js +++ b/5-network/08-xmlhttprequest/post.view/server.js @@ -17,7 +17,7 @@ function accept(req, res) { chunks.push(data); length += data.length; - // More than 10mb, kill the connection! + // 10mb를 넘으면 연결을 종료합니다! if (length > 1e8) { req.connection.destroy(); } @@ -28,16 +28,16 @@ function accept(req, res) { if (req.url == '/user') { res.writeHead(200, { 'Content-Type': 'application/json' }); - res.end(JSON.stringify({ message: 'User saved' })); + res.end(JSON.stringify({ message: '사용자 정보 저장 성공' })); } else if (req.url == '/image') { res.writeHead(200, { 'Content-Type': 'application/json' }); - res.end(JSON.stringify({ message: "Image saved", imageSize: length })); + res.end(JSON.stringify({ message: "이미지 저장 성공", imageSize: length })); } else if (req.url == '/upload') { res.writeHead(200, { 'Content-Type': 'application/json' }); - res.end(JSON.stringify({ message: "Upload complete", size: length })); + res.end(JSON.stringify({ message: "업로드 완료", size: length })); } else { res.writeHead(404); - res.end("Not found"); + res.end("찾을 수 없음"); } }); From 654b7873b6d141d6c84adf55937e242360251513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=ED=98=84=EC=9A=B0?= Date: Sun, 31 May 2026 20:13:27 +0900 Subject: [PATCH 2/4] =?UTF-8?q?docs:=20hello.txt=20=EB=B2=88=EC=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 5-network/08-xmlhttprequest/hello.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/5-network/08-xmlhttprequest/hello.txt b/5-network/08-xmlhttprequest/hello.txt index e3a3d9d343..e7223a96f8 100644 --- a/5-network/08-xmlhttprequest/hello.txt +++ b/5-network/08-xmlhttprequest/hello.txt @@ -1 +1 @@ -Hello from the server! +서버에서 보낸 인사입니다! From 2331790bb3a2d17bc88178585ba39651c542cb21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=ED=98=84=EC=9A=B0?= Date: Sun, 31 May 2026 20:13:55 +0900 Subject: [PATCH 3/4] =?UTF-8?q?docs:=20html,=20server.js=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20=EB=B2=88=EC=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 5-network/08-xmlhttprequest/example.view/index.html | 2 +- .../08-xmlhttprequest/phones-async.view/index.html | 10 +++++----- 5-network/08-xmlhttprequest/phones.view/index.html | 8 ++++---- 5-network/08-xmlhttprequest/phones.view/server.js | 2 +- 5-network/08-xmlhttprequest/post.view/index.html | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/5-network/08-xmlhttprequest/example.view/index.html b/5-network/08-xmlhttprequest/example.view/index.html index 7dbc3d9510..4ddde760b4 100644 --- a/5-network/08-xmlhttprequest/example.view/index.html +++ b/5-network/08-xmlhttprequest/example.view/index.html @@ -25,6 +25,6 @@ } - +
    diff --git a/5-network/08-xmlhttprequest/phones-async.view/index.html b/5-network/08-xmlhttprequest/phones-async.view/index.html index dff72ba3dc..2946643a76 100644 --- a/5-network/08-xmlhttprequest/phones-async.view/index.html +++ b/5-network/08-xmlhttprequest/phones-async.view/index.html @@ -5,7 +5,7 @@ - + diff --git a/5-network/08-xmlhttprequest/phones.view/index.html b/5-network/08-xmlhttprequest/phones.view/index.html index 02e1fb9674..2fcfedef9a 100644 --- a/5-network/08-xmlhttprequest/phones.view/index.html +++ b/5-network/08-xmlhttprequest/phones.view/index.html @@ -5,7 +5,7 @@ - + ``` -The form is sent with `multipart/form-data` encoding. +폼은 `multipart/form-data` 인코딩으로 전송됩니다. -Or, if we like JSON more, then `JSON.stringify` and send as a string. +또는 JSON이 더 좋다면 `JSON.stringify`로 문자열을 만들어 전송하면 됩니다. -Just don't forget to set the header `Content-Type: application/json`, many server-side frameworks automatically decode JSON with it: +다만 `Content-Type: application/json` 헤더를 설정하는 것을 잊지 마세요. 많은 서버 사이드 프레임워크가 이 헤더를 보고 JSON을 자동으로 디코딩합니다. ```js let xhr = new XMLHttpRequest(); @@ -390,45 +390,45 @@ xhr.setRequestHeader('Content-type', 'application/json; charset=utf-8'); xhr.send(json); ``` -The `.send(body)` method is pretty omnivore. It can send almost any `body`, including `Blob` and `BufferSource` objects. +`.send(body)` 메서드는 꽤 범용적입니다. `Blob`과 `BufferSource` 객체를 포함해 거의 모든 `body`를 보낼 수 있습니다. -## Upload progress +## 업로드 진행률 -The `progress` event triggers only on the downloading stage. +`progress` 이벤트는 다운로드 단계에서만 발생합니다. -That is: if we `POST` something, `XMLHttpRequest` first uploads our data (the request body), then downloads the response. +즉, `POST`로 무언가를 보내면 `XMLHttpRequest`는 먼저 데이터(요청 본문)를 업로드하고, 그다음 응답을 다운로드합니다. -If we're uploading something big, then we're surely more interested in tracking the upload progress. But `xhr.onprogress` doesn't help here. +큰 데이터를 업로드하는 경우엔 업로드 진행률을 추적하는 데 더 관심이 있을 것입니다. 하지만 이때 `xhr.onprogress`는 도움이 되지 않습니다. -There's another object, without methods, exclusively to track upload events: `xhr.upload`. +업로드 이벤트 추적 전용 객체인 `xhr.upload`가 따로 있습니다. 이 객체에는 메서드가 없습니다. -It generates events, similar to `xhr`, but `xhr.upload` triggers them solely on uploading: +`xhr.upload`는 `xhr`과 비슷하게 이벤트를 생성하지만, 오직 업로드 중에만 이벤트를 발생시킵니다. -- `loadstart` -- upload started. -- `progress` -- triggers periodically during the upload. -- `abort` -- upload aborted. -- `error` -- non-HTTP error. -- `load` -- upload finished successfully. -- `timeout` -- upload timed out (if `timeout` property is set). -- `loadend` -- upload finished with either success or error. +- `loadstart` -- 업로드가 시작됨. +- `progress` -- 업로드 중 주기적으로 발생함. +- `abort` -- 업로드가 중단됨. +- `error` -- HTTP와 무관한 에러. +- `load` -- 업로드가 성공적으로 완료됨. +- `timeout` -- 업로드 타임아웃(`timeout` 프로퍼티가 설정된 경우). +- `loadend` -- 성공이나 에러 여부와 관계없이 업로드가 끝남. -Example of handlers: +핸들러 예시는 다음과 같습니다. ```js xhr.upload.onprogress = function(event) { - alert(`Uploaded ${event.loaded} of ${event.total} bytes`); + alert(`${event.total} 바이트 중 ${event.loaded} 바이트 업로드됨`); }; xhr.upload.onload = function() { - alert(`Upload finished successfully.`); + alert(`업로드가 성공적으로 완료되었습니다.`); }; xhr.upload.onerror = function() { - alert(`Error during the upload: ${xhr.status}`); + alert(`업로드 중 에러 발생: ${xhr.status}`); }; ``` -Here's a real-life example: file upload with progress indication: +다음은 실제 예시입니다. 진행률 표시가 있는 파일 업로드입니다. ```html run @@ -437,19 +437,19 @@ Here's a real-life example: file upload with progress indication: function upload(file) { let xhr = new XMLHttpRequest(); - // track upload progress + // 업로드 진행률 추적 *!* xhr.upload.onprogress = function(event) { - console.log(`Uploaded ${event.loaded} of ${event.total}`); + console.log(`${event.total} 바이트 중 ${event.loaded} 바이트 업로드됨`); }; */!* - // track completion: both successful or not + // 성공 여부와 관계없이 완료 추적 xhr.onloadend = function() { if (xhr.status == 200) { - console.log("success"); + console.log("성공"); } else { - console.log("error " + this.status); + console.log("에러 " + this.status); } }; @@ -459,11 +459,11 @@ function upload(file) { ``` -## Cross-origin requests +## 크로스 오리진 요청 -`XMLHttpRequest` can make cross-origin requests, using the same CORS policy as [fetch](info:fetch-crossorigin). +`XMLHttpRequest`는 [fetch](info:fetch-crossorigin)와 같은 CORS 정책을 사용해 크로스 오리진 요청을 보낼 수 있습니다. -Just like `fetch`, it doesn't send cookies and HTTP-authorization to another origin by default. To enable them, set `xhr.withCredentials` to `true`: +`fetch`와 마찬가지로 기본적으로 다른 오리진에 쿠키와 HTTP 인증 정보를 보내지 않습니다. 이를 활성화하려면 `xhr.withCredentials`를 `true`로 설정하세요. ```js let xhr = new XMLHttpRequest(); @@ -475,12 +475,12 @@ xhr.open('POST', 'http://anywhere.com/request'); ... ``` -See the chapter for details about cross-origin headers. +크로스 오리진 헤더에 대한 자세한 내용은 챕터를 참고하세요. -## Summary +## 요약 -Typical code of the GET-request with `XMLHttpRequest`: +`XMLHttpRequest`로 GET 요청을 보내는 일반적인 코드는 다음과 같습니다. ```js let xhr = new XMLHttpRequest(); @@ -490,39 +490,39 @@ xhr.open('GET', '/my/url'); xhr.send(); xhr.onload = function() { - if (xhr.status != 200) { // HTTP error? - // handle error - alert( 'Error: ' + xhr.status); + if (xhr.status != 200) { // HTTP 에러? + // 에러 처리 + alert( '에러: ' + xhr.status); return; } - // get the response from xhr.response + // xhr.response에서 응답 가져오기 }; xhr.onprogress = function(event) { - // report progress - alert(`Loaded ${event.loaded} of ${event.total}`); + // 진행 상황 보고 + alert(`${event.total} 바이트 중 ${event.loaded} 바이트 로드됨`); }; xhr.onerror = function() { - // handle non-HTTP error (e.g. network down) + // HTTP와 무관한 에러 처리(예: 네트워크 끊김) }; ``` -There are actually more events, the [modern specification](https://xhr.spec.whatwg.org/#events) lists them (in the lifecycle order): +실제로는 이벤트가 더 많습니다. [최신 명세](https://xhr.spec.whatwg.org/#events)에는 수명 주기 순서대로 다음 이벤트가 나열되어 있습니다. -- `loadstart` -- the request has started. -- `progress` -- a data packet of the response has arrived, the whole response body at the moment is in `response`. -- `abort` -- the request was canceled by the call `xhr.abort()`. -- `error` -- connection error has occurred, e.g. wrong domain name. Doesn't happen for HTTP-errors like 404. -- `load` -- the request has finished successfully. -- `timeout` -- the request was canceled due to timeout (only happens if it was set). -- `loadend` -- triggers after `load`, `error`, `timeout` or `abort`. +- `loadstart` -- 요청이 시작됨. +- `progress` -- 응답의 데이터 패킷이 도착함. 이 시점까지 받은 응답 본문 전체는 `response`에 들어 있음. +- `abort` -- `xhr.abort()` 호출로 요청이 취소됨. +- `error` -- 연결 에러가 발생함. 예: 잘못된 도메인 이름. 404 같은 HTTP 에러에서는 발생하지 않음. +- `load` -- 요청이 성공적으로 완료됨. +- `timeout` -- 타임아웃으로 요청이 취소됨(설정된 경우에만 발생). +- `loadend` -- `load`, `error`, `timeout`, `abort` 후 발생함. -The `error`, `abort`, `timeout`, and `load` events are mutually exclusive. Only one of them may happen. +`error`, `abort`, `timeout`, `load` 이벤트는 상호 배타적입니다. 이들 중 하나만 발생할 수 있습니다. -The most used events are load completion (`load`), load failure (`error`), or we can use a single `loadend` handler and check the properties of the request object `xhr` to see what happened. +가장 자주 쓰는 이벤트는 로드 완료(`load`)와 로드 실패(`error`)입니다. 또는 단일 `loadend` 핸들러를 사용하고 요청 객체 `xhr`의 프로퍼티를 확인해 무슨 일이 일어났는지 판단할 수 있습니다. -We've already seen another event: `readystatechange`. Historically, it appeared long ago, before the specification settled. Nowadays, there's no need to use it, we can replace it with newer events, but it can often be found in older scripts. +`readystatechange`라는 이벤트도 이미 살펴봤습니다. 역사적으로 이 이벤트는 명세가 자리 잡기 전 오래전에 등장했습니다. 요즘은 사용할 필요가 없고, 더 새로운 이벤트로 대체할 수 있지만 오래된 스크립트에서는 자주 볼 수 있습니다. -If we need to track uploading specifically, then we should listen to same events on `xhr.upload` object. +업로드만 따로 추적해야 한다면 `xhr.upload` 객체에서 같은 이벤트를 감지하면 됩니다.