-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
tomcat/src/main/java/org/apache/coyote/http11/http/message/ResponseHeaders.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.apache.coyote.http11.http.message; | ||
|
||
import org.apache.coyote.http11.http.util.HttpResponseMessageHeader; | ||
|
||
import java.util.EnumMap; | ||
import java.util.Map; | ||
|
||
public class ResponseHeaders { | ||
|
||
private static final String MESSAGE_HEADERS_DELIMITER = ": "; | ||
private static final String SP = " "; | ||
private static final String CRLF = "\r\n"; | ||
|
||
private final Map<HttpResponseMessageHeader, String> headerValues; | ||
|
||
public ResponseHeaders() { | ||
this.headerValues = new EnumMap<>(HttpResponseMessageHeader.class); | ||
} | ||
|
||
public void setAttribute(final HttpResponseMessageHeader headerType, final String value) { | ||
headerValues.put(headerType, value); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
final StringBuilder stringBuilder = new StringBuilder(); | ||
for (final HttpResponseMessageHeader header : headerValues.keySet()) { | ||
stringBuilder.append(header.getValue()) | ||
.append(MESSAGE_HEADERS_DELIMITER) | ||
.append(headerValues.get(header)) | ||
.append(SP) | ||
.append(CRLF); | ||
} | ||
return stringBuilder.toString(); | ||
} | ||
} |