Skip to content

Commit

Permalink
fix: 헤더 알파벳 순 정렬 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyma-s committed Sep 4, 2023
1 parent 6ed967f commit 823621a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;

public class HttpHeaders {

Expand Down Expand Up @@ -101,9 +103,12 @@ public String getHeaderValue(final HttpHeaderName headerName) {

@Override
public String toString() {
final List<Entry<HttpHeaderName, String>> entrySet = headers.entrySet().stream()
.sorted(Entry.comparingByKey())
.collect(Collectors.toList());
final StringBuilder stringBuilder = new StringBuilder();

for (final Entry<HttpHeaderName, String> entry : headers.entrySet()) {
for (final Entry<HttpHeaderName, String> entry : entrySet) {
stringBuilder.append(entry.getKey().getValue())
.append(": ")
.append(entry.getValue())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ void fullUrl() throws IOException {
// then
final URL resource = getClass().getClassLoader().getResource("static/index.html");
var expected = "HTTP/1.1 200 OK\r\n" +
"Content-Type: text/html;charset=utf-8\r\n" +
"Content-Length: 5564\r\n" +
"Content-Type: text/html;charset=utf-8\r\n" +
"\r\n" +
new String(Files.readAllBytes(new File(resource.getFile()).toPath()));

Expand All @@ -63,8 +63,8 @@ void defaultUrl() throws IOException {
// then
final URL resource = getClass().getClassLoader().getResource("static/index.html");
var expected = "HTTP/1.1 200 OK\r\n" +
"Content-Type: text/html;charset=utf-8\r\n" +
"Content-Length: 5564\r\n" +
"Content-Type: text/html;charset=utf-8\r\n" +
"\r\n" +
new String(Files.readAllBytes(new File(resource.getFile()).toPath()));

Expand Down Expand Up @@ -95,8 +95,8 @@ void requestLoginPage() throws IOException {
// then
final URL resource = getClass().getClassLoader().getResource("static/login.html");
var expected = "HTTP/1.1 200 OK\r\n" +
"Content-Type: text/html;charset=utf-8\r\n" +
"Content-Length: 3797\r\n" +
"Content-Type: text/html;charset=utf-8\r\n" +
"\r\n" +
new String(Files.readAllBytes(new File(resource.getFile()).toPath()));

Expand Down Expand Up @@ -206,8 +206,8 @@ void requestRegisterPage() throws IOException {
// then
final URL resource = getClass().getClassLoader().getResource("static/register.html");
var expected = "HTTP/1.1 200 OK\r\n" +
"Content-Type: text/html;charset=utf-8\r\n" +
"Content-Length: 4319\r\n" +
"Content-Type: text/html;charset=utf-8\r\n" +
"\r\n" +
new String(Files.readAllBytes(new File(resource.getFile()).toPath()));

Expand Down

0 comments on commit 823621a

Please sign in to comment.