- ์ด๋ป๊ฒ ์น ์๋ฒ๊ฐ HTTP ํธ๋์ญ์ ์ ์ฒ๋ฆฌํ๋์ง ๋จ๊ณ๋ณ๋ก ์ค๋ช ํ๋ค.
- HTTP ํต์ ์ ์ง๋จํด์ฃผ๋ ๊ฐ๋จํ ์น ์๋ฒ๋ฅผ ์์ฑํด๋ณธ๋ค.
- ์ปค๋ฅ์ ์ ๋งบ๋๋ค - ํด๋ผ์ด์ธํธ์ ์ ์์ ๋ฐ์๋ค์ด๊ฑฐ๋, ์์น์๋ ํด๋ผ์ด์ธํธ๋ผ๋ฉด ๋ซ๋๋ค.
- ์์ฒญ์ ๋ฐ๋๋ค - HTTP ์์ฒญ ๋ฉ์์ง๋ฅผ ๋คํธ์ํฌ๋ก๋ถํฐ ์ฝ์ด๋ค์ธ๋ค.
- ์์ฒญ์ ์ฒ๋ฆฌํ๋ค - ์์ฒญ ๋ฉ์์ง๋ฅผ ํด์ํ๊ณ ํ๋์ ์ทจํ๋ค.
- ๋ฆฌ์์ค์ ์ ๊ทผํ๋ค - ๋ฉ์์ง์์ ์ง์ ํ ๋ฆฌ์์ค์ ์ ๊ทผํ๋ค.
- ์๋ต์ ๋ง๋ ๋ค - ์๋ต์ ํด๋ผ์ด์ธํธ์๊ฒ ๋๋ ค์ค๋ค.
- ์๋ต์ ๋ณด๋ธ๋ค - ์๋ต์ ํด๋ผ์ด์ธํธ์๊ฒ ๋๋ ค์ค๋ค
- ํธ๋์ญ์ ์ ๋ก๊ทธ๋ก ๋จ๊ธด๋ค - ๋ก๊ทธํ์ผ์ ํธ๋์ญ์ ์๋ฃ์ ๋ํ ๊ธฐ๋ก์ ๋จ๊ธด๋ค
web.server package์ web server๋ฅผ ๊ตฌํํ์๋ค. ๊ตฌ๋ ํ ๋ธ๋ผ์ฐ์ ์์ localhost:8080/index.html ๋ฅผ ์ฌ๋ ค ํ์ธํ ์ ์๋ค. ๊ธฐ์กด์ builder pattern์ ์ง์ ๊ตฌํํ๋ ๋ถ๋ถ์ lombok์ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ ์ด์ ๋ํ ์กฐ์น๋ฅผ ํด์ฃผ์ด์ผ ํ ์๋ ์๋ค.
https://docs.spring.io/spring/docs/3.0.0.M4/spring-framework-reference/html/ch15s02.html
- ์ปค๋ฅ์ ์ ๋งบ๋๋ค ServerSocket์ ์ฌ์ฉํ์ฌ ๊ตฌํํ์๋ค.
ServerSocket์๋ shutdownInput์ด๋ ๋ฉ์๋๊ฐ ์๋๋ฐ, 4์ฅ์์ gracefully shutdown๊ณผ ์ฐ๊ด๋ ๊ฐ๋ ์ด๋ผ ํจ๊ป ๋ณด๋ ๊ฒ์ ์ถ์ฒํ๋ค. https://stackoverflow.com/questions/15206605/purpose-of-socket-shutdownoutput
- ์์ฒญ ๋ฉ์์ง ์์
์์ฒญ์ค์ ํ์ฑํ์ฌ ์์ฒญ ๋ฉ์๋, ์ง์ ๋ ๋ฆฌ์์ค์ ์๋ณ์(URI), ๋ฒ์ ๋ฒํธ๋ฅผ ์ฐพ๋๋ค. ๋ฉ์์ง ํค๋๋ค์ ์ฝ๋๋ค. ํค๋์ ๋์ ์๋ฏธํ๋ ๋น ์ค์ ์ฐพ์๋ธ๋ค. ์์ฒญ ๋ณธ๋ฌธ์ด ์๋ค๋ฉด ์ฝ์ด๋ค์ธ๋ค. (๊ธธ์ด๋ Content-Length ํค๋๋ก ์ ์๋๋ค.)
๊ด๋ จํ์ฌ web.protocol.http.message ํจํค์ง์ ๋ด์ฉ์ ํ์ธํด๋ด๋ ์ข๋ค. ํนํ ResponseMessageFactory ํด๋์ค์์ ์๋ต ํจํท์ ๋ง๋ค๋ฉฐ ํด๋น ๋ถ๋ถ์ ์์ฑํ์์ผ๋ ํ์ธํด๋ด๋ ์ข๊ฒ ๋ค.
public static void response(ResponseMessage message, DataOutputStream dos) throws IOException {
String responseLine = getResponseLine(message);
String headers = getHeader(message);
dos.writeBytes(responseLine);
dos.writeBytes(headers);
dos.write(message.getEntityBody().getBody(), 0, message.getEntityBody().getBody().length);
dos.flush();
}
์ปค๋ฅ์ ์ ๋ ฅ/์ถ๋ ฅ ์ฒ๋ฆฌ ์ํคํ ์ฒ ๋จ์ผ ์ค๋ ๋ ์น ์๋ฒ, ๋ฉํฐํ๋ก์ธ์ค์ ๋ฉํฐํ๋ก์ธ์ค ์น์๋ฒ ๋ฑ์ ๋ํ ๋น๊ต๋ Apache MPM vs Nginx๋ก ๋์ฒดํ๋ค.
- ์์ฒญ ์ฒ๋ฆฌ
https://docs.spring.io/spring/docs/3.0.0.M4/spring-framework-reference/html/ch15s02.html
์์ฒญ์ ๋ํ ์ฒ๋ฆฌ๋ DispatcherServlet์ ๋์๋ฐฉ์์ ์๊ฐ์ ์ป์ด ์์ฑํ์๋ค. ํ์ฌ๋ RequestResolver class์์ index.html,style.css ๋ฑ ํ์ผ์ ๋ํ ์์ฒญ์ธ์ง /users์ ๊ฐ์ด Controller์ ๋ํ ์์ฒญ์ธ์ง๋ฅผ ํ๋จํ๋ฉฐ ๊ทธ ์ดํ ControllerResolver, ResourceResolver๊ฐ URL์ ๋ง๋ Controller๋ฅผ ๋ฆฌํดํ๊ฑฐ๋, ํ์ผ์ ์ฝ์ด ๋ฆฌํดํ๋ ๊ตฌ์กฐ๋ก ์ค๊ณํ์๋ค.
- ๋ฆฌ์์ค์ ๋งคํ๊ณผ ์ ๊ทผ (1) Docroot Apache web server๋ DocumentRoot๋ฅผ ๊ธฐ์ค์ผ๋ก ๋ฌธ์๋ฅผ ์ฝ์ผ๋ฉฐ ๊ทธ ์์์ ๊ฒฝ๋ก๋ ์ฝ๊ธฐ๋ฅผ ํ์ฉํ์ง ์๋๋ก, Directory listing์ ํ์ฉํ์ง ์๋๋ก ์ค์ ํด์ผ ํ๋ค.
<VirtualHost *:80>
DocumentRoot /data/www/hub
ServerName www.brainbackdoor.com
<Location />
RedirectMatch /(.*)$ https://www.brainbackdoor.com/$1
</Location>
ErrorLog "|/usr/sbin/cronolog /data/log/httpd/`hostname`/woowa.brainbackdoor.com/woowa.brainbackdoor.com_error_log_%Y%m%d"
CustomLog "|/usr/sbin/cronolog /data/log/httpd/`hostname`-time/woowa.brainbackdoor.com/woowa.brainbackdoor.com-%Y%m%d-%H" securityteam
</VirtualHost>
(2) DirectoryIndex
์น์๋ฒ์ ๋๋ ํ ๋ฆฌ ์ ๊ทผ์์ DirectoryIndex์์ ์ง์ ํ ํ์ผ(index.html ๋ฑ)์ ๋ฐํํ๋ค.
(3) ๋์ ์ปจํ ์ธ ๋ฆฌ์์ค ๋งคํ
ํน์ ์์ฒญ์ ๋ํด ScriptAlias ์์ฑ์ ํตํด CGI ์คํฌ๋ฆฝํธ๋ฅผ ํน์ ํ ์์น์์๋ง ์ ๊ณตํ๋๋ก ์ค์ ํ ์ ์๋ค.
(4) ์ ๊ทผ์ ์ด
์น ์๋ฒ๋ ํด๋ผ์ด์ธํธ์ IP ์ฃผ์์ ๊ทผ๊ฑฐํ์ฌ ์ ๊ทผ์ ์ ์ดํ ์ ์๊ณ ํน์ ๋ฆฌ์์ค์ ์ ๊ทผํ๋ ๋ฐ์ ์์ด ๋น๋ฐ๋ฒํธ๋ฅผ ๋ฌผ์ด๋ณผ ์ ์๋ค.
- ์๋ต ๋ง๋ค๊ธฐ
(1) ์๋ต ์ํฐํฐ : ResponseMessage
- ์๋ต ๋ณธ๋ฌธ์ MIME ํ์ ์ ์์ ํ๋ Content-Type ํค๋ (๋ฏธ๊ตฌํ)
- ์๋ต ๋ณธ๋ฌธ์ ๊ธธ์ด๋ฅผ ์์ ํ๋ Content-Length ํค๋
- ์ค์ ์๋ต ๋ณธ๋ฌธ์ ๋ด์ฉ
(2) ๋ฆฌ๋ค์ด๋ ์
- Location ์๋ตํค๋๋ฅผ์ ๊ทน์ ์ผ๋ก ํ์ฉํ๋ค.