org.apache.tomcat.util.http.parser.HttpParser Java Examples
The following examples show how to use
org.apache.tomcat.util.http.parser.HttpParser.
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: Http11InputBuffer.java From Tomcat8-Source-Read with MIT License | 6 votes |
public Http11InputBuffer(Request request, int headerBufferSize, boolean rejectIllegalHeaderName, HttpParser httpParser) { this.request = request; headers = request.getMimeHeaders(); this.headerBufferSize = headerBufferSize; this.rejectIllegalHeaderName = rejectIllegalHeaderName; this.httpParser = httpParser; filterLibrary = new InputFilter[0]; activeFilters = new InputFilter[0]; lastActiveFilter = -1; parsingHeader = true; parsingRequestLine = true; parsingRequestLinePhase = 0; parsingRequestLineEol = false; parsingRequestLineStart = 0; parsingRequestLineQPos = -1; headerParsePos = HeaderParsePosition.HEADER_START; swallowInput = true; inputStreamInputBuffer = new SocketInputBuffer(); }
Example #2
Source File: ApplicationPart.java From Tomcat8-Source-Read with MIT License | 5 votes |
@Override public String getSubmittedFileName() { String fileName = null; String cd = getHeader("Content-Disposition"); if (cd != null) { String cdl = cd.toLowerCase(Locale.ENGLISH); if (cdl.startsWith("form-data") || cdl.startsWith("attachment")) { ParameterParser paramParser = new ParameterParser(); paramParser.setLowerCaseNames(true); // Parameter parser can handle null input Map<String,String> params = paramParser.parse(cd, ';'); if (params.containsKey("filename")) { fileName = params.get("filename"); // The parser will remove surrounding '"' but will not // unquote any \x sequences. if (fileName != null) { // RFC 6266. This is either a token or a quoted-string if (fileName.indexOf('\\') > -1) { // This is a quoted-string fileName = HttpParser.unquote(fileName.trim()); } else { // This is a token fileName = fileName.trim(); } } else { // Even if there is no value, the parameter is present, // so we return an empty file name rather than no file // name. fileName = ""; } } } } return fileName; }
Example #3
Source File: DigestAuthenticator.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
public boolean parse(Request request, String authorization) { // Validate the authorization credentials format if (authorization == null) { return false; } Map<String,String> directives; try { directives = HttpParser.parseAuthorizationDigest( new StringReader(authorization)); } catch (IOException e) { return false; } if (directives == null) { return false; } method = request.getMethod(); userName = directives.get("username"); realmName = directives.get("realm"); nonce = directives.get("nonce"); nc = directives.get("nc"); cnonce = directives.get("cnonce"); qop = directives.get("qop"); uri = directives.get("uri"); response = directives.get("response"); opaqueReceived = directives.get("opaque"); return true; }
Example #4
Source File: Response.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
/** * Sets the content type. * * This method must preserve any response charset that may already have * been set via a call to response.setContentType(), response.setLocale(), * or response.setCharacterEncoding(). * * @param type the content type */ public void setContentType(String type) { if (type == null) { this.contentType = null; return; } MediaType m = null; try { m = HttpParser.parseMediaType(new StringReader(type)); } catch (IOException e) { // Ignore - null test below handles this } if (m == null) { // Invalid - Assume no charset and just pass through whatever // the user provided. this.contentType = type; return; } this.contentType = m.toStringNoCharset(); String charsetValue = m.getCharset(); if (charsetValue != null) { charsetValue = charsetValue.trim(); if (charsetValue.length() > 0) { charsetSet = true; this.characterEncoding = charsetValue; } } }
Example #5
Source File: DigestAuthenticator.java From tomcatsrc with Apache License 2.0 | 5 votes |
public boolean parse(Request request, String authorization) { // Validate the authorization credentials format if (authorization == null) { return false; } Map<String,String> directives; try { directives = HttpParser.parseAuthorizationDigest( new StringReader(authorization)); } catch (IOException e) { return false; } if (directives == null) { return false; } method = request.getMethod(); userName = directives.get("username"); realmName = directives.get("realm"); nonce = directives.get("nonce"); nc = directives.get("nc"); cnonce = directives.get("cnonce"); qop = directives.get("qop"); uri = directives.get("uri"); response = directives.get("response"); opaqueReceived = directives.get("opaque"); return true; }
Example #6
Source File: ApplicationPart.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Adapted from FileUploadBase.getFileName(). Method name chosen to be * consistent with Servlet 3.1. */ public String getSubmittedFileName() { String fileName = null; String cd = getHeader("Content-Disposition"); if (cd != null) { String cdl = cd.toLowerCase(Locale.ENGLISH); if (cdl.startsWith("form-data") || cdl.startsWith("attachment")) { ParameterParser paramParser = new ParameterParser(); paramParser.setLowerCaseNames(true); // Parameter parser can handle null input Map<String,String> params = paramParser.parse(cd, ';'); if (params.containsKey("filename")) { fileName = params.get("filename"); // The parser will remove surrounding '"' but will not // unquote any \x sequences. if (fileName != null) { // RFC 6266. This is either a token or a quoted-string if (fileName.indexOf('\\') > -1) { // This is a quoted-string fileName = HttpParser.unquote(fileName.trim()); } else { // This is a token fileName = fileName.trim(); } } else { // Even if there is no value, the parameter is present, // so we return an empty file name rather than no file // name. fileName = ""; } } } } return fileName; }
Example #7
Source File: Response.java From tomcatsrc with Apache License 2.0 | 5 votes |
/** * Sets the content type. * * This method must preserve any response charset that may already have * been set via a call to response.setContentType(), response.setLocale(), * or response.setCharacterEncoding(). * * @param type the content type */ public void setContentType(String type) { if (type == null) { this.contentType = null; return; } MediaType m = null; try { m = HttpParser.parseMediaType(new StringReader(type)); } catch (IOException e) { // Ignore - null test below handles this } if (m == null) { // Invalid - Assume no charset and just pass through whatever // the user provided. this.contentType = type; return; } this.contentType = m.toStringNoCharset(); String charsetValue = m.getCharset(); if (charsetValue != null) { charsetValue = charsetValue.trim(); if (charsetValue.length() > 0) { charsetSet = true; this.characterEncoding = charsetValue; } } }
Example #8
Source File: Http11Processor.java From Tomcat8-Source-Read with MIT License | 4 votes |
/** * Http11 NIO处理器. * 拿到连接.传递连接.处理连接.处理的关键地方. * 1.inputBuffer and outputBuffer绑定在了NioSocketWrapper. * 2. Http11Processor持有NioSocketWrapper对象. * 3. NioSocketWrapper去读写数据填充到对应的两个Buffer内. * @param protocol * @param endpoint */ @SuppressWarnings("deprecation") public Http11Processor(AbstractHttp11Protocol<?> protocol, AbstractEndpoint<?> endpoint) { super(endpoint); this.protocol = protocol; httpParser = new HttpParser(protocol.getRelaxedPathChars(), protocol.getRelaxedQueryChars()); /** * Http11 InputBuffer 绑定到 {@link org.apache.coyote.Request} */ inputBuffer = new Http11InputBuffer(request, protocol.getMaxHttpHeaderSize(), protocol.getRejectIllegalHeaderName(), httpParser); request.setInputBuffer(inputBuffer); /** * Http11 OutputBuffer 绑定到{@link org.apache.coyote.Response} */ outputBuffer = new Http11OutputBuffer(response, protocol.getMaxHttpHeaderSize(), protocol.getSendReasonPhrase()); response.setOutputBuffer(outputBuffer); // Create and add the identity filters. inputBuffer.addFilter(new IdentityInputFilter(protocol.getMaxSwallowSize())); outputBuffer.addFilter(new IdentityOutputFilter()); // Create and add the chunked filters. inputBuffer.addFilter(new ChunkedInputFilter(protocol.getMaxTrailerSize(), protocol.getAllowedTrailerHeadersInternal(), protocol.getMaxExtensionSize(), protocol.getMaxSwallowSize())); outputBuffer.addFilter(new ChunkedOutputFilter()); // Create and add the void filters. inputBuffer.addFilter(new VoidInputFilter()); outputBuffer.addFilter(new VoidOutputFilter()); // Create and add buffered input filter inputBuffer.addFilter(new BufferedInputFilter()); // Create and add the gzip filters. //inputBuffer.addFilter(new GzipInputFilter()); outputBuffer.addFilter(new GzipOutputFilter()); pluggableFilterIndex = inputBuffer.getFilters().length; }
Example #9
Source File: TLSClientHelloExtractor.java From Tomcat8-Source-Read with MIT License | 4 votes |
private static boolean isHttp(ByteBuffer bb) { // Based on code in Http11InputBuffer // Note: The actual request is not important. This code only checks that // the buffer contains a correctly formatted HTTP request line. // The method, target and protocol are not validated. byte chr = 0; bb.position(0); // Skip blank lines do { if (!bb.hasRemaining()) { return false; } chr = bb.get(); } while (chr == '\r' || chr == '\n'); // Read the method do { if (!HttpParser.isToken(chr) || !bb.hasRemaining()) { return false; } chr = bb.get(); } while (chr != ' ' && chr != '\t'); // Whitespace between method and target while (chr == ' ' || chr == '\t') { if (!bb.hasRemaining()) { return false; } chr = bb.get(); } // Read the target while (chr != ' ' && chr != '\t') { if (HttpParser.isNotRequestTarget(chr) || !bb.hasRemaining()) { return false; } chr = bb.get(); } // Whitespace between target and protocol while (chr == ' ' || chr == '\t') { if (!bb.hasRemaining()) { return false; } chr = bb.get(); } // Read protocol do { if (!HttpParser.isHttpProtocol(chr) || !bb.hasRemaining()) { return false; } chr = bb.get(); } while (chr != '\r' && chr != '\n'); return true; }