Java Code Examples for io.netty.util.AsciiString#cached()
The following examples show how to use
io.netty.util.AsciiString#cached() .
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: HttpMethod.java From PowerTunnel with MIT License | 6 votes |
/** * Creates a new HTTP method with the specified name. You will not need to * create a new method unless you are implementing a protocol derived from * HTTP, such as * <a href="http://en.wikipedia.org/wiki/Real_Time_Streaming_Protocol">RTSP</a> and * <a href="http://en.wikipedia.org/wiki/Internet_Content_Adaptation_Protocol">ICAP</a> */ public HttpMethod(String name) { name = checkNotNull(name, "name");//.trim(); if (name.isEmpty()) { throw new IllegalArgumentException("empty name"); } /*for (int i = 0; i < name.length(); i ++) { char c = name.charAt(i); if (Character.isISOControl(c) || Character.isWhitespace(c)) { throw new IllegalArgumentException("invalid character in name"); } }*/ this.name = name; this.asciiName = AsciiString.cached(name); }
Example 2
Source File: HttpMethod.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
/** * Creates a new HTTP method with the specified name. You will not need to * create a new method unless you are implementing a protocol derived from * HTTP, such as * <a href="http://en.wikipedia.org/wiki/Real_Time_Streaming_Protocol">RTSP</a> and * <a href="http://en.wikipedia.org/wiki/Internet_Content_Adaptation_Protocol">ICAP</a> * 创建具有指定名称的新HTTP方法。除非要实现从HTTP派生的协议(如RTSP和ICAP),否则不需要创建新方法 */ public HttpMethod(String name) { name = checkNotNull(name, "name").trim(); if (name.isEmpty()) { throw new IllegalArgumentException("empty name"); } for (int i = 0; i < name.length(); i ++) { char c = name.charAt(i); if (Character.isISOControl(c) || Character.isWhitespace(c)) { throw new IllegalArgumentException("invalid character in name"); } } this.name = AsciiString.cached(name); }
Example 3
Source File: CookieIntercept.java From proxyee-down with Apache License 2.0 | 6 votes |
@Override public void beforeRequest(Channel clientChannel, HttpRequest httpRequest, HttpProxyInterceptPipeline pipeline) throws Exception { String acceptValue = httpRequest.headers().get(HttpHeaderNames.ACCEPT); if (acceptValue != null && acceptValue.contains("application/x-sniff-cookie")) { HttpResponse httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, new DefaultHttpHeaders()); httpResponse.headers().set(HttpHeaderNames.CONTENT_LENGTH, 0); //https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Expose-Headers AsciiString customHeadKey = AsciiString.cached("X-Sniff-Cookie"); String cookie = pipeline.getHttpRequest().headers().get(HttpHeaderNames.COOKIE); httpResponse.headers().set(customHeadKey, cookie == null ? "" : cookie); httpResponse.headers().set(HttpHeaderNames.ACCESS_CONTROL_EXPOSE_HEADERS, customHeadKey); String origin = httpRequest.headers().get(HttpHeaderNames.ORIGIN); if (StringUtil.isNullOrEmpty(origin)) { String referer = httpRequest.headers().get(HttpHeaderNames.REFERER); URL url = new URL(referer); origin = url.getHost(); } httpResponse.headers().set(HttpHeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN, origin); httpResponse.headers().set(HttpHeaderNames.ACCESS_CONTROL_ALLOW_CREDENTIALS, true); clientChannel.writeAndFlush(httpResponse); clientChannel.writeAndFlush(new DefaultLastHttpContent()); clientChannel.close(); } else { super.beforeRequest(clientChannel, httpRequest, pipeline); } }
Example 4
Source File: ForwardingProxyOptions.java From quarkus with Apache License 2.0 | 5 votes |
public static ForwardingProxyOptions from(HttpConfiguration httpConfiguration) { final boolean proxyAddressForwarding = httpConfiguration.proxyAddressForwarding .orElse(httpConfiguration.proxy.proxyAddressForwarding); final boolean allowForwarded = httpConfiguration.allowForwarded .orElse(httpConfiguration.proxy.allowForwarded); final boolean enableForwardedHost = httpConfiguration.proxy.enableForwardedHost; final AsciiString forwardedHostHeader = AsciiString.cached(httpConfiguration.proxy.forwardedHostHeader); return new ForwardingProxyOptions(proxyAddressForwarding, allowForwarded, enableForwardedHost, forwardedHostHeader); }
Example 5
Source File: WebSocketScheme.java From netty-4.1.22 with Apache License 2.0 | 4 votes |
private WebSocketScheme(int port, String name) { this.port = port; this.name = AsciiString.cached(name); }
Example 6
Source File: HttpScheme.java From netty-4.1.22 with Apache License 2.0 | 4 votes |
private HttpScheme(int port, String name) { this.port = port; this.name = AsciiString.cached(name); }
Example 7
Source File: ReadOnlyHttpHeadersTest.java From netty-4.1.22 with Apache License 2.0 | 4 votes |
@Test(expected = IllegalArgumentException.class) public void validateNamesFail() { new ReadOnlyHttpHeaders(true, ACCEPT, APPLICATION_JSON, AsciiString.cached(" ")); }
Example 8
Source File: HpackStaticTable.java From netty-4.1.22 with Apache License 2.0 | 4 votes |
private static HpackHeaderField newEmptyHeaderField(String name) { return new HpackHeaderField(AsciiString.cached(name), AsciiString.EMPTY_STRING); }
Example 9
Source File: HpackStaticTable.java From netty-4.1.22 with Apache License 2.0 | 4 votes |
private static HpackHeaderField newHeaderField(String name, String value) { return new HpackHeaderField(AsciiString.cached(name), AsciiString.cached(value)); }
Example 10
Source File: HttpConversionUtil.java From netty-4.1.22 with Apache License 2.0 | 4 votes |
ExtensionHeaderNames(String text) { this.text = AsciiString.cached(text); }
Example 11
Source File: Http2Headers.java From netty-4.1.22 with Apache License 2.0 | 4 votes |
PseudoHeaderName(String value, boolean requestOnly) { this.value = AsciiString.cached(value); this.requestOnly = requestOnly; }
Example 12
Source File: DefaultController.java From proxyee-down with Apache License 2.0 | 4 votes |
private void buildHead(FullHttpResponse httpResponse, String mime) { if (mime != null) { AsciiString contentType; switch (mime) { case "txt": case "text": contentType = AsciiString.cached("text/plain; charset=utf-8"); break; case "html": case "htm": contentType = AsciiString.cached("text/html; charset=utf-8"); break; case "css": contentType = AsciiString.cached("text/css; charset=utf-8"); break; case "js": contentType = AsciiString.cached("application/javascript; charset=utf-8"); break; case "png": contentType = AsciiString.cached("image/png"); break; case "jpg": case "jpeg": contentType = AsciiString.cached("image/jpeg"); break; case "bmp": contentType = AsciiString.cached("application/x-bmp"); break; case "gif": contentType = AsciiString.cached("image/gif"); break; case "ico": contentType = AsciiString.cached("image/x-icon"); break; case "ttf": contentType = AsciiString.cached("font/ttf; charset=utf-8"); break; case "woff": contentType = AsciiString.cached("application/font-woff; charset=utf-8"); break; default: contentType = HttpHeaderValues.APPLICATION_OCTET_STREAM; } httpResponse.headers().set(HttpHeaderNames.CONTENT_TYPE, contentType); } }
Example 13
Source File: HttpHeaderNames.java From armeria with Apache License 2.0 | 4 votes |
private static AsciiString create(String name) { return AsciiString.cached(Ascii.toLowerCase(name)); }