<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Http on YuuuuuuYu</title><link>https://4d4cat.com/tags/http/</link><description>Recent content in Http on YuuuuuuYu</description><generator>Hugo -- 0.147.2</generator><language>ko-KR</language><lastBuildDate>Sat, 08 Nov 2025 15:02:23 +0900</lastBuildDate><atom:link href="https://4d4cat.com/tags/http/index.xml" rel="self" type="application/rss+xml"/><item><title>springframework.http.ResponseEntity</title><link>https://4d4cat.com/posts/2025/response-entity/</link><pubDate>Fri, 24 Jan 2025 11:05:00 +0900</pubDate><guid>https://4d4cat.com/posts/2025/response-entity/</guid><description>&lt;p>🔔 &lt;strong>ResponseEntity 개요&lt;/strong>&lt;br>
🔔 &lt;strong>다른 방법과 비교&lt;/strong>&lt;/p>
&lt;h2 id="what-why">&lt;strong>What? Why?&lt;/strong>&lt;/h2>
&lt;p>스프링 3 버전부터 도입되었으며, 스프링 MVC에서 HTTP 응답을 다루는 주요 클래스 중 하나이다. HTTP 응답의 전체 내용을 제어할 수 있도록 해주며, 이를 통해 다음과 같은 요소들을 설정할 수 있다.&lt;/p>
&lt;ul>
&lt;li>
&lt;p>상태 코드 (HTTP Status Code)&lt;br>
: 200 OK, 404 Not Found, 500 Internal Server Error 등&lt;/p>
&lt;/li>
&lt;li>
&lt;p>헤더 (Headers) &lt;br>
: 응답 헤더에 특정 값을 추가/수정&lt;/p>
&lt;/li>
&lt;li>
&lt;p>본문 (Body)&lt;br>
: 실제로 클라이언트에게 전달될 데이터&lt;/p>
&lt;/li>
&lt;/ul>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="nd">@GetMapping&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;/example&amp;#34;&lt;/span>&lt;span class="p">)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ResponseEntity&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="o">&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="nf">getExample&lt;/span>&lt;span class="p">()&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">body&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;Hello, World!&amp;#34;&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">HttpHeaders&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">headers&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="o">=&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">HttpHeaders&lt;/span>&lt;span class="p">();&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="n">headers&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">add&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s">&amp;#34;Custom-Header&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s">&amp;#34;CustomValue&amp;#34;&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="k">return&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="k">new&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">ResponseEntity&lt;/span>&lt;span class="o">&amp;lt;&amp;gt;&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="n">body&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">headers&lt;/span>&lt;span class="p">,&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">HttpStatus&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="na">OK&lt;/span>&lt;span class="p">);&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="responsebody">&lt;strong>@ResponseBody&lt;/strong>&lt;/h3>
&lt;p>객체를 직렬화하여 반환하는 어노테이션으로, 이것만 사용할 경우 헤더를 유연하게 설정할 수 없다.&lt;br>
&lt;code>@ResopnseStatus&lt;/code>를 사용하여 헤더를 설정할 수 있지만, 어노테이션을 별도로 추가해야하는 단점이 있다.&lt;/p></description></item><item><title>HttpClient Deepdive</title><link>https://4d4cat.com/posts/2025/httpclient-deepdive/</link><pubDate>Sun, 12 Jan 2025 17:37:00 +0900</pubDate><guid>https://4d4cat.com/posts/2025/httpclient-deepdive/</guid><description>&lt;p>🔔 &lt;strong>BodyPublisher, BodyHandler 역할&lt;/strong>&lt;br>
🔔 &lt;strong>HttpClient 실습&lt;/strong>&lt;/p>
&lt;h2 id="bodypublisher-bodyhandler">&lt;strong>BodyPublisher? BodyHandler?&lt;/strong>&lt;/h2>
&lt;p>&lt;code>BodyPublisher&lt;/code>와 &lt;code>BodyHandlers&lt;/code>는 요청과 응답의 본문을 처리하는 데 있어 상호 보완적인 역할을 한다. &lt;code>BodyPublisher&lt;/code>는 클라이언트가 서버로 전송할 데이터를 정의하고, &lt;code>BodyHandlers&lt;/code>는 서버로부터 받은 데이터를 어떻게 처리할지를 정의한다. 이 두 구성 요소를 적절히 활용하면, HTTP 통신을 더욱 유연하고 효율적으로 구현할 수 있다.&lt;/p>
&lt;h3 id="bodypublisher">&lt;strong>BodyPublisher&lt;/strong>&lt;/h3>
&lt;ul>
&lt;li>HTTP 요청의 본문을 제공&lt;/li>
&lt;li>데이터를 전송할 때 어떻게 제공할지 정의
&lt;ul>
&lt;li>&lt;code>BodyPublishers.ofString(String)&lt;/code>: 문자열 데이터&lt;/li>
&lt;li>&lt;code>BodyPublishers.ofByteArray(byte[])&lt;/code>: 바이트 배열 데이터&lt;/li>
&lt;li>&lt;code>BodyPublishers.ofFile(Path)&lt;/code>: 파일 데이터&lt;/li>
&lt;li>&lt;code>BodyPublishers.ofInputStream(Supplier&amp;lt;InputStream&amp;gt;)&lt;/code>: 동적으로 생성되는 입력 스트림&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;h3 id="bodyhandler">&lt;strong>BodyHandler&lt;/strong>&lt;/h3>
&lt;ul>
&lt;li>HTTP 응답의 본문을 처리하는 방법을 정의&lt;/li>
&lt;li>서버로부터 받은 응답 데이터를 어떻게 처리할지 정의
&lt;ul>
&lt;li>&lt;code>BodyHandlers.ofString()&lt;/code>: 문자열 데이터&lt;/li>
&lt;li>&lt;code>BodyHandlers.ofByteArray()&lt;/code>: 바이트 배열 데이터&lt;/li>
&lt;li>&lt;code>BodyHandlers.ofFile(Path)&lt;/code>: 파일 데이터&lt;/li>
&lt;li>&lt;code>BodyHandlers.ofInputStream()&lt;/code>: &lt;code>InputStream&lt;/code>으로 데이터 제공&lt;/li>
&lt;/ul>
&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>HttpResponse.BodyHandler 클래스는 BodyHandler를 생성하기 위한 여러 가지 편리한 정적 팩토리 메서드를 제공한다. 이들 중 다수는 응답 바이트가 완전히 수신될 때까지 메모리에 축적되며, 그 후 응답 바이트는 상위 수준의 Java 유형(ofString, ofByteArray 등)으로 변환된다.&lt;/p></description></item><item><title>java.net.http.HttpClient</title><link>https://4d4cat.com/posts/2025/httpclient/</link><pubDate>Fri, 10 Jan 2025 16:43:00 +0900</pubDate><guid>https://4d4cat.com/posts/2025/httpclient/</guid><description>&lt;p>🔔 &lt;strong>HttpClient 개요&lt;/strong>&lt;br>
🔔 &lt;strong>HttpClient 개선 과정&lt;/strong>&lt;br>
🔔 &lt;strong>다른 라이브러리 비교&lt;/strong>&lt;/p>
&lt;h2 id="what-why">&lt;strong>What? Why?&lt;/strong>&lt;/h2>
&lt;p>자바에서 HTTP 요청을 생성하고, 서버와 통신하며, 응답을 처리하기 위한 API &lt;br>
Java 11에서 표준 라이브러리로 도입되었으며, 이전의 &lt;code>HttpURLConnection&lt;/code>보다 사용하기 쉽고 기능이 풍부하다.&lt;/p>
&lt;ul>
&lt;li>빌더 패턴 도입: &lt;code>HttpRequest&lt;/code>.newBuilder()&lt;/li>
&lt;li>역할 분리: &lt;code>HttpClient&lt;/code>, &lt;code>HttpRequest&lt;/code>, &lt;code>HttpResponse&lt;/code>&lt;/li>
&lt;li>비동기 처리 지원: &lt;code>HttpClient&lt;/code>.sendAsync()&lt;/li>
&lt;/ul>
&lt;h3 id="주요-클래스">&lt;strong>주요 클래스&lt;/strong>&lt;/h3>
&lt;ul>
&lt;li>&lt;code>HttpClient&lt;/code>: HTTP 요청을 보내기 위한 클라이언트 객체를 생성&lt;/li>
&lt;li>&lt;code>HttpRequest&lt;/code>: HTTP 요청의 세부 사항(URI, 메서드, 헤더 등)&lt;/li>
&lt;li>&lt;code>HttpResponse&lt;/code>: 서버로부터 받은 HTTP 응답&lt;/li>
&lt;/ul>
&lt;h3 id="주요-메서드">&lt;strong>주요 메서드&lt;/strong>&lt;/h3>
&lt;ul>
&lt;li>&lt;code>HttpClient&lt;/code>.newHttpClient()&lt;/li>
&lt;/ul>
&lt;blockquote>
&lt;p>기본 설정을 사용한 HttpClient 인스턴스를 생성 &lt;br>
- 요청(GET), 프로토콜(HTTP/2), 리다이렉트(NEVER), SSL(Default)&lt;/p></description></item><item><title>HTTPS</title><link>https://4d4cat.com/posts/2024/https/</link><pubDate>Wed, 06 Nov 2024 18:32:00 +0900</pubDate><guid>https://4d4cat.com/posts/2024/https/</guid><description>&lt;h2 id="https-http-secure">HTTPS (HTTP Secure)&lt;/h2>
&lt;p>: HTTP의 보안이 강화된 버전이다. 소켓 통신에서 일반 텍스트를 이용하는 대신에, SSL이나 TLS 프로토콜을 통해 세션 데이터를 암호화한다.&lt;/p>
&lt;h3 id="1-http와의-차이점">1. HTTP와의 차이점&lt;/h3>
&lt;p>&lt;img loading="lazy" src="https://4d4cat.com/images/2024/https0.png">&lt;/p>
&lt;p>요약하면 HTTPS는 다음과 같은 차이점이 있다.&lt;/p>
&lt;ul>
&lt;li>&lt;strong>보안성&lt;/strong>: 보안 인증서를 통해 데이터 전송 시 암호화를 제공하여 보안을 강화&lt;/li>
&lt;li>&lt;strong>무결성&lt;/strong>: 데이터가 전송 중에 변경되지 않았음을 보장&lt;/li>
&lt;li>&lt;strong>신뢰성&lt;/strong>: 검색 엔진에서 우선순위를 우대받으며, 사용자에게 더 신뢰감을 보장&lt;/li>
&lt;/ul>
&lt;h3 id="2-동작-원리">2. 동작 원리&lt;/h3>
&lt;p>&lt;img loading="lazy" src="https://4d4cat.com/images/2024/https1.png">&lt;/p>
&lt;dl>
&lt;dt>&lt;strong>1) URL 파싱 및 DNS 조회&lt;/strong>&lt;/dt>
&lt;dd>브라우저는 URL을 확인하고 DNS를 통해 도메인을 IP 주소로 변환하여 전달한다.&lt;/dd>
&lt;dt>&lt;strong>2) 보안 연결 설정&lt;/strong>&lt;/dt>
&lt;dd>서버는 &lt;code>TLS&lt;/code> handshake를 통해 인증서를 클라이언트에 전송한다. &lt;br>
이 인증서에는 서버의 공개 키와 인증기관(CA)의 서명이 포함되어 있다.&lt;/dd>
&lt;dt>&lt;strong>3) 서버 처리 및 응답 생성&lt;/strong>&lt;/dt>
&lt;dd>보안 연결이 설정되면 암호화된 요청을 서버로 보낸다.&lt;br>
서버는 요청을 해독하여 요청된 데이터, 상태코드 등으로 구성된 HTTPS 응답을 생성한다.&lt;/dd>
&lt;dt>&lt;strong>4) 응답 암호화 및 전송&lt;/strong>&lt;/dt>
&lt;dd>서버는 TLS를 이용하여 응답을 암호화하고 클라이언트의 브라우저로 다시 전송한다. &lt;br>
이 암호화를 통해 전송되는 동안 데이터의 보안이 유지되고 데이터를 가로채더라도 내용을 해독할 수 없다.&lt;/dd>
&lt;dt>&lt;strong>5) 클라이언트에서의 처리&lt;/strong>&lt;/dt>
&lt;dd>암호화된 응답을 수신한 브라우저는 이를 해독한다.&lt;br>
여기에는 웹 페이지를 표시하도록 렌더링하는 작업이 포함된다. &lt;br>
데이터가 완전히 전송되고 렌더링되면 TLS 연결은 종료된다.&lt;/dd>
&lt;/dl>
&lt;h3 id="3-전달-내용-비교">3. 전달 내용 비교&lt;/h3>
&lt;p>&lt;strong>ex) HTTP 요청 (평문 전송)&lt;/strong>&lt;/p></description></item><item><title>HTTP</title><link>https://4d4cat.com/posts/2024/http/</link><pubDate>Mon, 04 Nov 2024 14:46:00 +0900</pubDate><guid>https://4d4cat.com/posts/2024/http/</guid><description>&lt;h2 id="http-hypertext-transfer-protocol">HTTP (HyperText Transfer Protocol)&lt;/h2>
&lt;p>: &lt;strong>웹상에서 데이터를 송수신하기 위한 통신 규약&lt;/strong>으로 클라이언트와 서버 사이에 이루어지는 요청/응답 프로토콜이다. 예를 들어 클라이언트인 웹 브라우저가 &lt;code>HTTP&lt;/code>를 통하여 서버로부터 웹 페이지(HTML) 등 정보를 요청하면, 서버는 이 요청에 응답하여 필요한 정보를 사용자에게 전달한다.&lt;/p>
&lt;blockquote>
&lt;p>🔔 &lt;strong>HTTPS를 정리하기 전, 최소한의 HTTP 정보만 정리한 것으로 일부 개념이 생략되어있습니다.&lt;/strong>&lt;/p>&lt;/blockquote>
&lt;h2 id="http-요청">HTTP 요청&lt;/h2>
&lt;p>: HTTP 요청을 할 때, 서로 다른 유형의 정보를 전달하는 일련의 인코딩된 데이터를 전달한다.&lt;/p>
&lt;hr>
&lt;p>&lt;img loading="lazy" src="https://4d4cat.com/images/2024/http0.png">&lt;/p>
&lt;h3 id="1-http-버전-유형">1. HTTP 버전 유형&lt;/h3>
&lt;p>HTTP 버전은 시간이 지나면서 여러 버전으로 업데이트되어 왔습니다. &lt;br>
간단히 요약하면 아래와 같은데 자세한 내용은 RFC 문서를 참고하시기 바랍니다. &lt;br> &lt;br>
&lt;img loading="lazy" src="https://4d4cat.com/images/2024/http1.png">&lt;/p></description></item></channel></rss>