use of cn.taketoday.http.DefaultHttpHeaders in project today-infrastructure by TAKETODAY.
the class MockMultipartFile method createHttpHeaders.
protected DefaultHttpHeaders createHttpHeaders() {
DefaultHttpHeaders headers = HttpHeaders.create();
headers.set(HttpHeaders.CONTENT_TYPE, getContentType());
return headers;
}
use of cn.taketoday.http.DefaultHttpHeaders in project today-framework by TAKETODAY.
the class Utils method readHeaders.
/**
* Reads headers from the given stream. Headers are read according to the
* RFC, including folded headers, element lists, and multiple headers
* (which are concatenated into a single element list header).
* Leading and trailing whitespace is removed.
*
* @param in the stream from which the headers are read
* @param config light http config
* @return the read headers (possibly empty, if none exist)
* @throws IOException if an IO error occurs or the headers are malformed
* or there are more than 100 header lines
* @see LightHttpConfig#getHeaderMaxCount()
*/
public static HttpHeaders readHeaders(InputStream in, LightHttpConfig config) throws IOException {
DefaultHttpHeaders headers = new DefaultHttpHeaders();
String line;
String prevLine = Constant.BLANK;
int count = 0;
while ((line = readLine(in)).length() > 0) {
// start of line data (after whitespace)
int start;
final int length = line.length();
//
for (start = 0; start < length && Character.isWhitespace(line.charAt(start)); start++) ;
if (// unfold header continuation line
start > 0)
line = prevLine + ' ' + line.substring(start);
int separator = line.indexOf(':');
if (separator < 0)
throw new IOException("invalid header: \"" + line + "\"");
String name = line.substring(0, separator);
// ignore LWS
String value = line.substring(separator + 1).trim();
headers.add(name, value);
prevLine = line;
if (++count > config.getHeaderMaxCount())
throw new IOException("too many header lines");
}
return headers;
}
Aggregations