Skip to content

Commit

Permalink
refactor: 응답 구분자 상수화
Browse files Browse the repository at this point in the history
  • Loading branch information
youngh0 committed Sep 4, 2023
1 parent 09a3871 commit fdd145d
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

public class ResponseEntity {

public static final String EXTENSION_DELIMITER = ".";
public static final String RESPONSE_DELIMITER = " ";

private final HttpVersion httpVersion;
private final ResponseStatus responseStatus;
private final List<String> responseHeaders;
Expand All @@ -25,12 +28,12 @@ public ResponseEntity(HttpVersion httpVersion, ResponseStatus responseStatus, Li
}

public static ResponseEntity redirect(String redirectionFile) {
List<String> headers = List.of(String.join(" ", "Location:", redirectionFile));
List<String> headers = List.of(String.join(RESPONSE_DELIMITER, "Location:", redirectionFile));
return new ResponseEntity(HttpVersion.HTTP_1_1, ResponseStatus.FOUND, headers, "");
}

public static ResponseEntity ok(String fileData, String endPoint) {
int fileTypeStartIndex = endPoint.indexOf('.');
int fileTypeStartIndex = endPoint.indexOf(EXTENSION_DELIMITER);
String fileExtension = endPoint.substring(fileTypeStartIndex + 1);

List<String> headers = List.of(
Expand All @@ -56,7 +59,7 @@ public String generateResponseMessage() {

private String generateStatus() {
return String.join(
" ",
RESPONSE_DELIMITER,
httpVersion.getVersion(),
String.valueOf(responseStatus.getStatusCode()),
responseStatus.name(),
Expand All @@ -68,7 +71,7 @@ private String generateHeader() {
StringJoiner headers = new StringJoiner("\r\n");
for (String header : responseHeaders) {
headers.add(
String.join(" ", header, "")
String.join(RESPONSE_DELIMITER, header, "")
);
}
if (cookies.containsKey("JSESSIONID")) {
Expand Down

0 comments on commit fdd145d

Please sign in to comment.