-
Notifications
You must be signed in to change notification settings - Fork 311
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
[π± Tomcat ꡬννκΈ° 1λ¨κ³] μ μ°μ€(μ μ¬μ°) λ―Έμ μ μΆν©λλ€. #552
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μλ νμΈμ μ μ°μ€ !
κΌΌκΌΌνκ² λ―Έμ μνν΄μ£Όμ ¨λ€μ π μ μ ν ν΄λμ€ λΆλ¦¬λ ν΄μ£Όμ΄μ μ½κ² μ½μ μ μμμ΅λλ€.
μ½λ μ€κ³λ HTTPμ λν μ¬λ μλ μ΄μΌκΈ°λ λ€μ λ―Έμ μ μ§νν νμ μ¬λ―Έμκ² λλ 보면 μ’μ κ² κ°μμ. μλ² λ¨κ³μμλ κ°λ³κ² μ§λ¬Έμ΄λ μ°Έκ³ νλ©΄ μ’μ λΆλΆμ λ¦¬λ·°λ‘ λ¨κ²¨λμμ΅λλ€!
μκ³ λ§μΌμ ¨μ΄μ. μ¦κ±°μ΄ μ£Όλ§ λμΈμ! π
if (!filename.isEmpty()) { | ||
final var classLoader = getClass().getClassLoader(); | ||
final var url = classLoader.getResource("static/" + filename); | ||
final var resourcePath = Path.of(url.getPath()); | ||
|
||
responseBody = Files.readString(resourcePath); | ||
|
||
} else { | ||
responseBody = "Hello world!"; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
responseBody
λ₯Ό "Hello,World!"λ‘ λν΄νΈλ‘ κ³ μ νκ³ , νμΌ μ΄λ¦μ΄ μλ κ²½μ° λ€λ₯Έ μ²λ¦¬λ₯Ό ν΄μ£Όλ©΄
else` ꡬ문μ μ κ±°ν μ μκ² λ€μ !
final var _protocolVersion = requestLineSplit[2]; | ||
|
||
final var filename = path.replace("/", ""); | ||
final var request = new HttpRequest(inputStream); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
κ°μ²΄μ§ν₯ π
var line = reader.readLine(); | ||
while (line != null) { | ||
body.add(line); | ||
line = reader.readLine(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while
쑰건문 λ΄μμ readLine()
μ μννλ λ°©μμΌλ‘ νλ©΄ μ’μ κ² κ°μμ !
public static final String TEXT_HTML = "text/html"; | ||
public static final String TEXT_CSS = "text/css"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CSSμ HTMLμ λν΄ λ€λ₯Έ MediaTypeμ μ λ¬ν΄μ£Όλ©΄ μ΄λ€ λμ λ°©μμ μ°¨μ΄κ° μλμ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μλ²κ° CSS νμΌμ μλ΅λ©΄μ Content-Typeμ κ°μ text/html
λ‘ λ³΄λ΄λ©΄ λΈλΌμ°μ κ° html νμΌλ‘ μΈμνκΈ° λλ¬Έμ CSS λμνμ§ μμμ. λΈλΌμ°μ μ CSS νμΌμ ν
μ€νΈλ‘ μΆλ ₯νκ² λ©λλ€.
λ―Έμ μ μ§ννλ©΄μ μμ²μ Accept ν€λλ₯Ό ν΅ν΄ λ³΄κ³ μλ΅μ Content-Typeμ κ²°μ νλ λ‘μ§μ΄ λ€μ΄κ°λλ‘ κ΅¬νν μκ°μ΄μμ π
private String extension(final String path) { | ||
final var index = path.lastIndexOf("."); | ||
return path.substring(index + 1); | ||
private String mapResource(final HttpRequest request) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ν°μΊ£μ ServletContainerκ° νλ μν μ μ λ©μλκ° ν΄μ£Όκ³ μλ€μ!
μΆνμ ν°μΊ£μ λμ λ°©μμ μ°Έκ³ ν΄ λ¦¬ν©ν λ§ν΄λ³΄λ©΄ μ¬λ°μ κ² κ°μμ~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λͺ°λλ κ°λ μΈλ° μλ €μ€μ κ³ λ§μμ!
ν΄λΉ ν€μλλ‘ κ³΅λΆν΄λ³Όκ²μ π
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ£Όλ§ μ 보λ΄μ ¨λμ μλ π
리뷰 λλΆμ 곡λΆνκΈ° μ’μ ν€μλ μμκ°λλ€ πββοΈ
μΆκ° μ½λ©νΈ μλ€λ©΄ ν΄μ£Όμ λ μ’κ³ , Approve ν΄μ£Όμλ©΄ λΉ λ₯΄κ² 2λ¨κ³ ꡬνν΄ μ¬κ²μ!
public static final String TEXT_HTML = "text/html"; | ||
public static final String TEXT_CSS = "text/css"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μλ²κ° CSS νμΌμ μλ΅λ©΄μ Content-Typeμ κ°μ text/html
λ‘ λ³΄λ΄λ©΄ λΈλΌμ°μ κ° html νμΌλ‘ μΈμνκΈ° λλ¬Έμ CSS λμνμ§ μμμ. λΈλΌμ°μ μ CSS νμΌμ ν
μ€νΈλ‘ μΆλ ₯νκ² λ©λλ€.
λ―Έμ μ μ§ννλ©΄μ μμ²μ Accept ν€λλ₯Ό ν΅ν΄ λ³΄κ³ μλ΅μ Content-Typeμ κ²°μ νλ λ‘μ§μ΄ λ€μ΄κ°λλ‘ κ΅¬νν μκ°μ΄μμ π
private String extension(final String path) { | ||
final var index = path.lastIndexOf("."); | ||
return path.substring(index + 1); | ||
private String mapResource(final HttpRequest request) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λͺ°λλ κ°λ μΈλ° μλ €μ€μ κ³ λ§μμ!
ν΄λΉ ν€μλλ‘ κ³΅λΆν΄λ³Όκ²μ π
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μλ νμΈμ μ μ°μ€ ~
μ΄λ² λ¨κ³μμλ λΉ λ₯΄κ² λμ΄κ°κ³ λ€μ 리뷰μμ μ¬λ―Έμλ μ΄μΌκΈ° λ§μ΄ ν΄λ΄μ.
λ°μκ² μ§λ§ νλ΄μκΈ° λ°λλλ€! πππ
μλ νμΈμ μλ π
νλ‘μ νΈμ λ―Έμ μ λ³ννλ κ² μ½μ§ μλ€μ π
μν λ³λ‘ ν΄λμ€λ₯Ό λΆλ¦¬νλ €λ€ μκ°μ΄ λΆμ‘±ν΄ Http11Processorμ λλΆλΆμ λ‘μ§μ λλ €λ£μ μν©μ΄μμ.
κ·Έλ°λ° μκ³ λ³΄λ 3λ¨κ³μ 리ν©ν λ§μ΄ μμ λμ΄ μλλΌκ΅¬μ.
κ·Έλμ κ°μ²΄ κ° μν λΆλ¦¬μ κ΄λ ¨λ 리뷰λ 3λ¨κ³μ λΆνλ릴κ²μ.
κ·Έ μΈμλ νΈνκ² λ¦¬λ·°ν΄μ£Όμλ©΄ κ³ λ§κ² μ΅λλ€!
μ°Έκ³ λ‘, λ³Έ PRμλ 1λ¨κ³μ ν΄λΉνλ μ½λλ§ ν¬ν¨λμ΄ μμ΅λλ€.
리뷰 μ λΆνλλ €μ!