Java Code Examples for org.apache.coyote.Response#getMimeHeaders()
The following examples show how to use
org.apache.coyote.Response#getMimeHeaders() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TomcatHttpHandlerAdapter.java From spring-analysis-note with MIT License | 5 votes |
private static HttpHeaders createTomcatHttpHeaders(HttpServletResponse response) { ResponseFacade responseFacade = getResponseFacade(response); org.apache.catalina.connector.Response connectorResponse = (org.apache.catalina.connector.Response) ReflectionUtils.getField(COYOTE_RESPONSE_FIELD, responseFacade); Assert.state(connectorResponse != null, "No Tomcat connector response"); Response tomcatResponse = connectorResponse.getCoyoteResponse(); TomcatHeadersAdapter headers = new TomcatHeadersAdapter(tomcatResponse.getMimeHeaders()); return new HttpHeaders(headers); }
Example 2
Source File: TomcatHttpHandlerAdapter.java From java-technology-stack with MIT License | 5 votes |
private static HttpHeaders createTomcatHttpHeaders(HttpServletResponse response) { ResponseFacade responseFacade = getResponseFacade(response); org.apache.catalina.connector.Response connectorResponse = (org.apache.catalina.connector.Response) ReflectionUtils.getField(COYOTE_RESPONSE_FIELD, responseFacade); Assert.state(connectorResponse != null, "No Tomcat connector response"); Response tomcatResponse = connectorResponse.getCoyoteResponse(); TomcatHeadersAdapter headers = new TomcatHeadersAdapter(tomcatResponse.getMimeHeaders()); return new HttpHeaders(headers); }
Example 3
Source File: TomcatService.java From armeria with Apache License 2.0 | 5 votes |
private static ResponseHeaders convertResponse(Response coyoteRes) { final ResponseHeadersBuilder headers = ResponseHeaders.builder(); headers.status(coyoteRes.getStatus()); final String contentType = coyoteRes.getContentType(); if (contentType != null && !contentType.isEmpty()) { headers.set(HttpHeaderNames.CONTENT_TYPE, contentType); } final long contentLength = coyoteRes.getBytesWritten(true); // 'true' will trigger flush. final String method = coyoteRes.getRequest().method().toString(); if (!"HEAD".equals(method)) { headers.setLong(HttpHeaderNames.CONTENT_LENGTH, contentLength); } final MimeHeaders cHeaders = coyoteRes.getMimeHeaders(); final int numHeaders = cHeaders.size(); for (int i = 0; i < numHeaders; i++) { final AsciiString name = toHeaderName(cHeaders.getName(i)); if (name == null) { continue; } final String value = toHeaderValue(cHeaders.getValue(i)); if (value == null) { continue; } headers.add(name.toLowerCase(), value); } return headers.build(); }
Example 4
Source File: StreamProcessor.java From Tomcat8-Source-Read with MIT License | 4 votes |
static void prepareHeaders(Request coyoteRequest, Response coyoteResponse, Http2Protocol protocol, Stream stream) { MimeHeaders headers = coyoteResponse.getMimeHeaders(); int statusCode = coyoteResponse.getStatus(); // Add the pseudo header for status headers.addValue(":status").setString(Integer.toString(statusCode)); // Check to see if a response body is present if (!(statusCode < 200 || statusCode == 204 || statusCode == 205 || statusCode == 304)) { String contentType = coyoteResponse.getContentType(); if (contentType != null) { headers.setValue("content-type").setString(contentType); } String contentLanguage = coyoteResponse.getContentLanguage(); if (contentLanguage != null) { headers.setValue("content-language").setString(contentLanguage); } // Add a content-length header if a content length has been set unless // the application has already added one long contentLength = coyoteResponse.getContentLengthLong(); if (contentLength != -1 && headers.getValue("content-length") == null) { headers.addValue("content-length").setLong(contentLength); } } else { if (statusCode == 205) { // RFC 7231 requires the server to explicitly signal an empty // response in this case coyoteResponse.setContentLength(0); } else { coyoteResponse.setContentLength(-1); } } // Add date header unless it is an informational response or the // application has already set one if (statusCode >= 200 && headers.getValue("date") == null) { headers.addValue("date").setString(FastHttpDateFormat.getCurrentDate()); } if (protocol != null && protocol.useCompression(coyoteRequest, coyoteResponse)) { // Enable compression. Headers will have been set. Need to configure // output filter at this point. stream.addOutputFilter(new GzipOutputFilter()); } }