use of cn.taketoday.http.DefaultHttpHeaders in project today-infrastructure by TAKETODAY.
the class PartHttpMessageWriter method encodePart.
private Flux<DataBuffer> encodePart(byte[] boundary, Part part, DataBufferFactory bufferFactory) {
DefaultHttpHeaders headers = new DefaultHttpHeaders(part.headers());
String name = part.name();
if (!headers.containsKey(HttpHeaders.CONTENT_DISPOSITION)) {
headers.setContentDispositionFormData(name, part instanceof FilePart ? ((FilePart) part).filename() : null);
}
return Flux.concat(generateBoundaryLine(boundary, bufferFactory), generatePartHeaders(headers, bufferFactory), part.content(), generateNewLine(bufferFactory));
}
use of cn.taketoday.http.DefaultHttpHeaders in project today-infrastructure by TAKETODAY.
the class ServletServerHttpRequest method initHeaders.
private static MultiValueMap<String, String> initHeaders(MultiValueMap<String, String> headerValues, HttpServletRequest request) {
HttpHeaders headers = null;
MediaType contentType = null;
if (StringUtils.isEmpty(headerValues.getFirst(HttpHeaders.CONTENT_TYPE))) {
String requestContentType = request.getContentType();
if (StringUtils.isNotEmpty(requestContentType)) {
contentType = MediaType.parseMediaType(requestContentType);
headers = new DefaultHttpHeaders(headerValues);
headers.setContentType(contentType);
}
}
if (contentType != null && contentType.getCharset() == null) {
String encoding = request.getCharacterEncoding();
if (StringUtils.isNotEmpty(encoding)) {
Map<String, String> params = new LinkedCaseInsensitiveMap<>();
params.putAll(contentType.getParameters());
params.put("charset", Charset.forName(encoding).toString());
headers.setContentType(new MediaType(contentType, params));
}
}
if (headerValues.getFirst(HttpHeaders.CONTENT_TYPE) == null) {
int contentLength = request.getContentLength();
if (contentLength != -1) {
headers = (headers != null ? headers : new DefaultHttpHeaders(headerValues));
headers.setContentLength(contentLength);
}
}
return (headers != null ? headers : headerValues);
}
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 HttpResponse method send.
/**
* Sends the full response with the given status, and the given string
* as the body. The text is sent in the UTF-8 charset. If a
* Content-Type header was not explicitly set, it will be set to
* text/html, and so the text must contain valid (and properly
* {@link Utils#escapeHTML escaped}) HTML.
*
* @param status the response status
* @param text the text body (sent as text/html)
* @throws IOException if an error occurs
* @see HttpStatus
*/
public void send(final HttpStatus status, final String text) throws IOException {
this.status = status;
if (text != null) {
final byte[] content = text.getBytes(StandardCharsets.UTF_8);
final DefaultHttpHeaders headers = this.headers;
headers.setETag("W/\"" + Integer.toHexString(text.hashCode()) + "\"");
headers.set(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_HTML_VALUE);
write(status, headers, ResponseOutputBuffer.ofBytes(content));
} else {
write(status, headers, null);
}
}
use of cn.taketoday.http.DefaultHttpHeaders in project today-framework by TAKETODAY.
the class PartHttpMessageWriter method encodePart.
private Flux<DataBuffer> encodePart(byte[] boundary, Part part, DataBufferFactory bufferFactory) {
DefaultHttpHeaders headers = new DefaultHttpHeaders(part.headers());
String name = part.name();
if (!headers.containsKey(HttpHeaders.CONTENT_DISPOSITION)) {
headers.setContentDispositionFormData(name, part instanceof FilePart ? ((FilePart) part).filename() : null);
}
return Flux.concat(generateBoundaryLine(boundary, bufferFactory), generatePartHeaders(headers, bufferFactory), part.content(), generateNewLine(bufferFactory));
}
Aggregations