private static HttpHeaders convertResponse(Response coyoteRes) { final HttpHeaders headers = HttpHeaders.of(HttpStatus.valueOf(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; }
request.getCoyoteRequest().getMimeHeaders() .getValue("authorization"); authorization.toBytes(); ByteChunk authorizationBC = authorization.getByteChunk(); if (authorizationBC.startsWithIgnoreCase("basic ", 0)) { authorizationBC.setOffset(authorizationBC.getOffset() + 6); CharChunk authorizationCC = authorization.getCharChunk(); Base64.decode(authorizationBC, authorizationCC); try { MessageBytes authenticate = response.getCoyoteResponse().getMimeHeaders() .addValue(AUTHENTICATE_BYTES, 0, AUTHENTICATE_BYTES.length); CharChunk authenticateCC = authenticate.getCharChunk(); authenticateCC.append("Basic realm=\""); authenticateCC.append('\"'); authenticate.toChars(); response.sendError(HttpServletResponse.SC_UNAUTHORIZED); return new AuthResult(TomcatAuthStatus.SEND_CONTINUE, null); } catch (IOException e) {
rframe.associated = 0; MimeHeaders headers = response.getMimeHeaders(); for (int i = 0; i < headers.size(); i++) { MessageBytes mb = headers.getName(i); mb.toBytes(); ByteChunk bc = mb.getByteChunk(); byte[] bb = bc.getBuffer(); for (int j = bc.getStart(); j < bc.getEnd(); j++) { bb[j] = (byte) Ascii.toLower(bb[j]); if (response.getStatus() == 0) { rframe.addHeader(SpdyFrame.STATUS, SpdyFrame.OK200); } else { && HttpMessages.isSafeInHttpHeader(response.getMessage())) { message = response.getMessage(); response.getLocale()).getMessage(response.getStatus()); message = Integer.toString(response.getStatus()); String status = response.getStatus() + " " + message; byte[] statusB = status.getBytes(); rframe.headerName(SpdyFrame.STATUS, 0, SpdyFrame.STATUS.length);
/* */ public String[] getHeaderNames() /* */ { /* 859 */ MimeHeaders headers = this.coyoteResponse.getMimeHeaders(); /* 860 */ int n = headers.size(); /* 861 */ String[] result = new String[n]; /* 862 */ for (int i = 0; i < n; i++) { /* 863 */ result[i] = headers.getName(i).toString(); /* */ } /* 865 */ return result; /* */ } /* */
MessageBytes acceptEncodingMB = request.getMimeHeaders().getValue("accept-encoding"); if ((acceptEncodingMB == null) || (acceptEncodingMB.indexOf("gzip") == -1)) return false; MessageBytes contentEncodingMB = response.getMimeHeaders().getValue("Content-Encoding"); if ((contentEncodingMB != null) && (contentEncodingMB.indexOf("gzip") != -1)) return false; MessageBytes userAgentValueMB = request.getMimeHeaders().getValue("user-agent"); if (userAgentValueMB != null) { String userAgentValue = userAgentValueMB.toString(); long contentLength = response.getContentLengthLong(); if ((contentLength == -1) || (contentLength > compressionMinSize)) { return (startsWithStringArray(compressableMimeTypes, response.getContentType()));
protected void parseHost(MessageBytes valueMB) { if (valueMB == null || valueMB.isNull()) { populateHost(); return; char c = (char) valueB[i + valueS]; if (c < '0' || c > '9') { response.setStatus(400); setErrorState(ErrorState.CLOSE_CLEAN, null); return; request.setServerPort(port); hostNameC[i] = (char) valueB[i + valueS]; request.serverName().setChars(hostNameC, 0, valueL); String message = sm.getString("abstractProcessor.hostInvalid", valueMB.toString()); switch (logMode) { case INFO_THEN_DEBUG: message += sm.getString("abstractProcessor.fallToDebug"); response.setStatus(400); setErrorState(ErrorState.CLOSE_CLEAN, e);
/* */ public void sendError(int status, String message) /* */ throws IOException /* */ { /* 1188 */ if (isCommitted()) { /* 1189 */ throw new IllegalStateException(sm.getString("coyoteResponse.sendError.ise")); /* */ } /* */ /* 1193 */ if (this.included) { /* 1194 */ return; /* */ } /* 1196 */ Wrapper wrapper = getRequest().getWrapper(); /* 1197 */ if (wrapper != null) { /* 1198 */ wrapper.incrementErrorCount(); /* */ } /* */ /* 1201 */ setError(); /* */ /* 1203 */ this.coyoteResponse.setStatus(status); /* 1204 */ this.coyoteResponse.setMessage(message); /* */ /* 1207 */ resetBuffer(); /* */ /* 1210 */ setSuspended(true); /* */ } /* */
if ((!coyoteResponse.isCommitted()) && (coyoteResponse.getContentLengthLong() == -1)) { if (!coyoteResponse.isCommitted()) { coyoteResponse.setContentLength(bb.getLength()); Request req = (Request) coyoteResponse.getRequest().getNote( CoyoteAdapter.ADAPTER_NOTES); req.inputBuffer.close(); coyoteResponse.finish();
/** * Flush bytes or chars contained in the buffer. * * @throws IOException An underlying IOException occurred */ protected void doFlush(boolean realFlush) throws IOException { if (suspended) return; doFlush = true; if (initial) { coyoteResponse.sendHeaders(); initial = false; } if (bb.getLength() > 0) { bb.flushBuffer(); } doFlush = false; if (realFlush) { coyoteResponse.action(ActionCode.CLIENT_FLUSH, coyoteResponse); // If some exception occurred earlier, or if some IOE occurred // here, notify the servlet with an IOE if (coyoteResponse.isExceptionPresent()) { throw new ClientAbortException (coyoteResponse.getErrorException()); } } }
public void service(Request req, final Response res) throws Exception { MessageBytes mb = req.requestURI(); String uri = req.requestURI().toString(); if (uri.indexOf("..") >= 0) { res.setStatus(404); return; res.setStatus(404); return; res.setStatus(404); return; res.setStatus(200); String ct=getContentType(ext); if( ct!=null) { res.setContentType(ct); res.setContentLength((int)resource.length()); res.sendHeaders(); ByteChunk chunk = new ByteChunk(); int rd = 0; while ((rd = fis.read(b)) > 0) { chunk.setBytes(b, 0, rd); res.doWrite(chunk); res.finish();
/** Called by the processor before recycling the request. It'll collect * statistic information. */ void updateCounters() { bytesReceived+=req.getBytesRead(); bytesSent+=req.getResponse().getContentWritten(); requestCount++; if( req.getResponse().getStatus() >=400 ) errorCount++; long t0=req.getStartTime(); long t1=System.currentTimeMillis(); long time=t1-t0; this.lastRequestProcessingTime = time; processingTime+=time; if( maxTime < time ) { maxTime=time; maxRequestUri=req.requestURI().toString(); } }
public SocketState event(SocketStatus status) throws IOException { RequestInfo rp = request.getRequestProcessor(); try { if (status == SocketStatus.OPEN_CALLBACK) { error = true; } catch (Throwable t) { log.error(sm.getString("http11processor.request.process"), t); response.setStatus(500); error = true;
/** * Intercept the request and decide if we cache the static resource. If the * static resource is already cached, return it. */ public int handle(Request req, int handlerCode) throws IOException{ if (fileCache == null) return Handler.CONTINUE; if (handlerCode == Handler.RESPONSE_PROCEEDED && fileCache.isEnabled()){ String docroot = SelectorThread.getWebAppRootPath(); MessageBytes mb = req.requestURI(); ByteChunk requestURI = mb.getByteChunk(); String uri = req.requestURI().toString(); fileCache.add(FileCache.DEFAULT_SERVLET_NAME,docroot,uri, req.getResponse().getMimeHeaders(),false); } else if (handlerCode == Handler.HEADERS_PARSED) { ByteChunk requestURI = req.requestURI().getByteChunk(); if (fileCache.sendCache(requestURI.getBytes(), requestURI.getStart(), requestURI.getLength(), socketChannel, keepAlive(req))){ return Handler.BREAK; } } return Handler.CONTINUE; }
contentDelimitation = false; if (sslSupport != null) { request.scheme().setString("https"); MessageBytes protocolMB = request.protocol(); if (protocolMB.equals(Constants.HTTP_11)) { http11 = true; protocolMB.setString(Constants.HTTP_11); } else if (protocolMB.equals(Constants.HTTP_10)) { http11 = false; error = true; response.setStatus(505); MessageBytes connectionValueMB = headers.getValue("connection"); if (connectionValueMB != null) { ByteChunk connectionValueBC = connectionValueMB.getByteChunk();
/** Called by the processor before recycling the request. It'll collect * statistic information. */ void updateCounters() { bytesReceived+=req.getBytesRead(); bytesSent+=req.getResponse().getBytesWritten(); requestCount++; if( req.getResponse().getStatus() >=400 ) errorCount++; long t0=req.getStartTime(); long t1=System.currentTimeMillis(); long time=t1-t0; this.lastRequestProcessingTime = time; processingTime+=time; if( maxTime < time ) { maxTime=time; maxRequestUri=req.requestURI().toString(); } }
request.getMimeHeaders().getValue("accept-encoding"); || (acceptEncodingMB.indexOf("gzip") == -1)) return false; response.getMimeHeaders().getValue("Content-Encoding"); && (contentEncodingMB.indexOf("gzip") != -1)) return false; request.getMimeHeaders().getValue("user-agent"); if (userAgentValueMB != null) { String userAgentValue = userAgentValueMB.toString(); int contentLength = response.getContentLength(); if ((contentLength == -1) || (contentLength > compressionMinSize)) { response.getContentType()));
return; Request request = response.getRequest(); if (request.getUpgradeHandler() != null && request.isEventMode()) { request.getEvent().close(); return; if ((!coyoteResponse.isCommitted()) && (coyoteResponse.getContentLengthLong() == -1)) { if (!coyoteResponse.isCommitted()) { coyoteResponse.setContentLength(bb.getLength()); closed = true; coyoteResponse.finish();
/** * {@inheritDoc} * <p> * This implementation populates the server name and port from the local * name and port provided by the AJP message. */ @Override protected void populateHost() { // No host information (HTTP/1.0) request.setServerPort(request.getLocalPort()); try { request.serverName().duplicate(request.localName()); } catch (IOException e) { response.setStatus(400); setErrorState(ErrorState.CLOSE_CLEAN, e); } }
response.setError(); boolean blockIo = this.errorState.isIoAllowed() && !errorState.isIoAllowed(); this.errorState = this.errorState.getMostSevere(errorState); if (response.getStatus() < 400 && !(t instanceof IOException)) { response.setStatus(500); request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, t); getLog().debug(sm.getString("abstractProcessor.nonContainerThreadError"), t);
/** * Alternate constructor. */ public InternalOutputBuffer(Response response, int headerBufferSize) { this.response = response; headers = response.getMimeHeaders(); buf = new byte[headerBufferSize]; outputStreamOutputBuffer = new OutputStreamOutputBuffer(); filterLibrary = new OutputFilter[0]; activeFilters = new OutputFilter[0]; lastActiveFilter = -1; socketBuffer = new ByteChunk(); socketBuffer.setByteOutputChannel(this); committed = false; finished = false; }