-
Notifications
You must be signed in to change notification settings - Fork 0
대소문자를 구분하지 않는 Attributes #75
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
base: freddie-noel
Are you sure you want to change the base?
Changes from 4 commits
5106c52
532ad2e
c698959
76a3235
0d3fa81
b0ee9ae
0c06f60
780f6e9
2851f2a
dfe49f7
49d127e
66dcf7c
f61aa7f
8dbb272
41592da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,36 +16,55 @@ public static Attributes from(Map<String, String> attributes) { | |
| } | ||
|
|
||
| public static Attributes from(String headerText) { | ||
| Map<String, String> attributes = new LinkedHashMap<>(); | ||
| Attributes attributes = new Attributes(); | ||
|
|
||
| String[] splittedHeaderTexts = headerText.split(Const.CRLF); | ||
| for (String splittedHeaderText : splittedHeaderTexts) { | ||
| HttpRequestUtils.Pair pair = HttpRequestUtils.parseHeader(splittedHeaderText); | ||
|
|
||
| if (pair != null) { | ||
| attributes.put(pair.getKey(), pair.getValue()); | ||
| attributes.add(pair.getKey(), pair.getValue()); | ||
| } | ||
| } | ||
|
|
||
| return from(attributes); | ||
| return attributes; | ||
| } | ||
|
|
||
| public Attributes add(String key, String value) { | ||
| for (String k : attributes.keySet()) { | ||
|
||
| if (k.equalsIgnoreCase(key)) { | ||
| return this; | ||
| } | ||
| } | ||
|
|
||
| attributes.put(key, value); | ||
| return this; | ||
| } | ||
|
|
||
| public Attributes addAll(Map<String, String> attributes) { | ||
| this.attributes.putAll(attributes); | ||
| for (String key : attributes.keySet()) { | ||
| add(key, attributes.get(key)); | ||
| } | ||
|
|
||
| return this; | ||
| } | ||
|
|
||
| public String get(String key) { | ||
| return attributes.get(key); | ||
| for (String k : attributes.keySet()) { | ||
| if (k.equalsIgnoreCase(key)) { | ||
| return attributes.get(k); | ||
| } | ||
| } | ||
Dae-Hwa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return null; | ||
|
||
| } | ||
|
|
||
| public String getOrDefault(String key, String defaultValue) { | ||
| return attributes.getOrDefault(key, defaultValue); | ||
| for (String k : attributes.keySet()) { | ||
| if (k.equalsIgnoreCase(key)) { | ||
| return attributes.get(k); | ||
| } | ||
| } | ||
| return defaultValue; | ||
|
||
| } | ||
|
|
||
| public String toHeaderText() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,13 @@ | ||
| package webserver.http.statusline; | ||
|
|
||
| import webserver.http.attribute.Attributes; | ||
|
|
||
| import java.net.URI; | ||
| import java.net.URISyntaxException; | ||
| import java.util.*; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.StringJoiner; | ||
|
|
||
| public class RequestStatusLine extends StatusLine { | ||
|
|
||
|
|
@@ -13,12 +18,16 @@ public RequestStatusLine(Map<String, String> statusLineAttributes) { | |
| super(statusLineAttributes); | ||
| } | ||
|
|
||
| public RequestStatusLine(Attributes statusLineAttributes) { | ||
| super(statusLineAttributes); | ||
| } | ||
|
|
||
| public static RequestStatusLine from(List<String> statusLine) { | ||
| Map<String, String> statusLineAttributes = new HashMap<>(); | ||
| Attributes statusLineAttributes = new Attributes(); | ||
|
|
||
| statusLineAttributes.put(METHOD_KEY, statusLine.get(0)); | ||
| statusLineAttributes.put(PATH_KEY, statusLine.get(1)); | ||
| statusLineAttributes.put(PROTOCOL_VERSION_KEY, statusLine.get(2)); | ||
| statusLineAttributes.add(METHOD_KEY, statusLine.get(0)); | ||
| statusLineAttributes.add(PATH_KEY, statusLine.get(1)); | ||
| statusLineAttributes.add(PROTOCOL_VERSION_KEY, statusLine.get(2)); | ||
|
Comment on lines
+26
to
+
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 부분도 Attributes를 만들면서 자연스럽게 검증이 될 테니 Map으로 받아줘도 괜찮을 것 같아요
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그게 아니라 생성자로 Attributes를 넣어주는게 더 바람직하다고 생각하신거면 좋은 방법인 것 같습니다 |
||
|
|
||
| return new RequestStatusLine(statusLineAttributes); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| package webserver.http.attribute; | ||
|
|
||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.params.ParameterizedTest; | ||
| import org.junit.jupiter.params.provider.Arguments; | ||
|
|
@@ -11,6 +12,8 @@ | |
| import java.util.stream.Stream; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.junit.jupiter.api.Assertions.assertAll; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| class AttributesTest { | ||
|
|
||
|
|
@@ -40,12 +43,20 @@ void fromHeaderText() { | |
| } | ||
|
|
||
| @Test | ||
| @DisplayName("add 테스트: key의 대소문자 관계 없이 Attributes를 꺼내올 수 있음") | ||
| void add() { | ||
| Attributes attributes = new Attributes(); | ||
| attributes.add("key", "value"); | ||
|
|
||
| assertAll( | ||
| () -> assertEquals("value", attributes.get("KEY")), | ||
| () -> assertEquals("value", attributes.get("key")), | ||
| () -> assertEquals("value", attributes.get("kEy")) | ||
| ); | ||
|
||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("addAll 테스트: key의 대소문자 관계 없이 Attributes를 꺼내올 수 있음") | ||
| void addAll() { | ||
| Attributes attributes = new Attributes(); | ||
| Map<String, String> attributeMap = new LinkedHashMap<>(); | ||
|
|
@@ -55,7 +66,11 @@ void addAll() { | |
| Attributes expectedAttributes = new Attributes(); | ||
| expectedAttributes.add("key", "value"); | ||
|
|
||
| assertThat(attributes).isEqualTo(expectedAttributes); | ||
| assertAll( | ||
| () -> assertEquals(expectedAttributes.get("key"), attributes.get("KEY")), | ||
| () -> assertEquals(expectedAttributes.get("KEY"), attributes.get("kEY")), | ||
| () -> assertEquals(expectedAttributes.get("kEy"), attributes.get("key")) | ||
|
||
| ); | ||
| } | ||
|
|
||
| @Test | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.