index
int64
repo_id
string
file_path
string
content
string
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpMethodParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; final class HttpMethodParser extends Parser<HttpMethod> { final HttpParser http; final StringBuilder name; final int step; HttpMethodParser(HttpParser http, StringBuilder name, int step) { this.http = http; this.name = name; this.step = step; } HttpMethodParser(HttpParser http) { this(http, null, 1); } @Override public Parser<HttpMethod> feed(Input input) { return parse(input, this.http, this.name, this.step); } static Parser<HttpMethod> parse(Input input, HttpParser http, StringBuilder name, int step) { int c = 0; if (step == 1) { if (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); name = new StringBuilder(); name.appendCodePoint(c); step = 2; } else { return error(Diagnostic.expected("HTTP method", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("HTTP method", input)); } } if (step == 2) { while (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); name.appendCodePoint(c); } else { break; } } if (!input.isEmpty()) { return done(http.method(name.toString())); } } if (input.isError()) { return error(input.trap()); } return new HttpMethodParser(http, name, step); } static Parser<HttpMethod> parse(Input input, HttpParser http) { return parse(input, http, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Decoder; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.InputBuffer; import swim.codec.Parser; import swim.codec.Unicode; import swim.collections.FingerTrieSeq; import swim.collections.HashTrieMap; import swim.http.header.Accept; import swim.http.header.AcceptCharset; import swim.http.header.AcceptEncoding; import swim.http.header.AcceptLanguage; import swim.http.header.Allow; import swim.http.header.Connection; import swim.http.header.ContentEncoding; import swim.http.header.ContentLength; import swim.http.header.ContentType; import swim.http.header.Expect; import swim.http.header.Host; import swim.http.header.MaxForwards; import swim.http.header.Origin; import swim.http.header.RawHeader; import swim.http.header.SecWebSocketAccept; import swim.http.header.SecWebSocketExtensions; import swim.http.header.SecWebSocketKey; import swim.http.header.SecWebSocketProtocol; import swim.http.header.SecWebSocketVersion; import swim.http.header.Server; import swim.http.header.TransferEncoding; import swim.http.header.Upgrade; import swim.http.header.UserAgent; import swim.uri.Uri; public class HttpParser { public <T> HttpRequest<T> request(HttpMethod method, Uri uri, HttpVersion version, FingerTrieSeq<HttpHeader> headers) { return HttpRequest.from(method, uri, version, headers); } public <T> HttpResponse<T> response(HttpVersion version, HttpStatus status, FingerTrieSeq<HttpHeader> headers) { return HttpResponse.from(version, status, headers); } public HttpMethod method(String name) { return HttpMethod.from(name); } public HttpStatus status(int code, String phrase) { return HttpStatus.from(code, phrase); } public HttpVersion version(int major, int minor) { return HttpVersion.from(major, minor); } public HttpChunkHeader chunkHeader(long size, FingerTrieSeq<ChunkExtension> extensions) { return HttpChunkHeader.from(size, extensions); } public HttpChunkTrailer chunkTrailer(FingerTrieSeq<HttpHeader> headers) { return HttpChunkTrailer.from(headers); } public ChunkExtension chunkExtension(String name, String value) { return ChunkExtension.from(name, value); } public HttpCharset charset(String name, float weight) { return HttpCharset.from(name, weight); } public LanguageRange languageRange(String tag, String subtag, float weight) { return LanguageRange.from(tag, subtag, weight); } public MediaRange mediaRange(String type, String subtype, float weight, HashTrieMap<String, String> params) { return MediaRange.from(type, subtype, weight, params); } public MediaType mediaType(String type, String subtype, HashTrieMap<String, String> params) { return MediaType.from(type, subtype, params); } public Product product(String name, String version, FingerTrieSeq<String> comments) { return Product.from(name, version, comments); } public ContentCoding contentCoding(String name, float weight) { return ContentCoding.from(name, weight); } public TransferCoding transferCoding(String name, HashTrieMap<String, String> params) { return TransferCoding.from(name, params); } public UpgradeProtocol upgradeProtocol(String name, String version) { return UpgradeProtocol.from(name, version); } public WebSocketParam webSocketParam(String key, String value) { return WebSocketParam.from(key, value); } public WebSocketExtension webSocketExtension(String name, FingerTrieSeq<WebSocketParam> params) { return WebSocketExtension.from(name, params); } public <T> Parser<HttpRequest<T>> requestParser() { return new HttpRequestParser<T>(this); } public <T> Parser<HttpRequest<T>> parseRequest(Input input) { return HttpRequestParser.parse(input, this); } public <T> HttpRequest<T> parseRequestString(String string) { final Input input = Unicode.stringInput(string); Parser<HttpRequest<T>> parser = parseRequest(input); if (input.isCont() && !parser.isError()) { parser = Parser.error(Diagnostic.unexpected(input)); } return parser.bind(); } public <T> Parser<HttpResponse<T>> responseParser() { return new HttpResponseParser<T>(this); } public <T> Parser<HttpResponse<T>> parseResponse(Input input) { return HttpResponseParser.parse(input, this); } public <T> HttpResponse<T> parseResponseString(String string) { final Input input = Unicode.stringInput(string); Parser<HttpResponse<T>> parser = parseResponse(input); if (input.isCont() && !parser.isError()) { parser = Parser.error(Diagnostic.unexpected(input)); } return parser.bind(); } public Parser<HttpMethod> methodParser() { return new HttpMethodParser(this); } public Parser<HttpMethod> parseMethod(Input input) { return HttpMethodParser.parse(input, this); } public HttpMethod parseMethodString(String string) { final Input input = Unicode.stringInput(string); Parser<HttpMethod> parser = parseMethod(input); if (input.isCont() && !parser.isError()) { parser = Parser.error(Diagnostic.unexpected(input)); } return parser.bind(); } public Parser<HttpStatus> statusParser() { return new HttpStatusParser(this); } public Parser<HttpStatus> parseStatus(Input input) { return HttpStatusParser.parse(input, this); } public HttpStatus parseStatusString(String string) { final Input input = Unicode.stringInput(string); Parser<HttpStatus> parser = parseStatus(input); if (input.isCont() && !parser.isError()) { parser = Parser.error(Diagnostic.unexpected(input)); } return parser.bind(); } public Parser<HttpVersion> versionParser() { return new HttpVersionParser(this); } public Parser<HttpVersion> parseVersion(Input input) { return HttpVersionParser.parse(input, this); } public HttpVersion parseVersionString(String string) { final Input input = Unicode.stringInput(string); Parser<HttpVersion> parser = parseVersion(input); if (input.isCont() && !parser.isError()) { parser = Parser.error(Diagnostic.unexpected(input)); } return parser.bind(); } public Parser<HttpHeader> headerParser() { return new HttpHeaderParser(this); } public Parser<HttpHeader> parseHeader(Input input) { return HttpHeaderParser.parse(input, this); } public HttpHeader parseHeaderString(String string) { final Input input = Unicode.stringInput(string); Parser<? extends HttpHeader> parser = parseHeader(input); if (input.isCont() && !parser.isError()) { parser = Parser.error(Diagnostic.unexpected(input)); } return parser.bind(); } public Parser<? extends HttpHeader> parseHeaderValue(String name, Input input) { if ("Accept".equalsIgnoreCase(name)) { return Accept.parseHttpValue(input, this); } else if ("Accept-Charset".equalsIgnoreCase(name)) { return AcceptCharset.parseHttpValue(input, this); } else if ("Accept-Encoding".equalsIgnoreCase(name)) { return AcceptEncoding.parseHttpValue(input, this); } else if ("Accept-Language".equalsIgnoreCase(name)) { return AcceptLanguage.parseHttpValue(input, this); } else if ("Allow".equalsIgnoreCase(name)) { return Allow.parseHttpValue(input, this); } else if ("Connection".equalsIgnoreCase(name)) { return Connection.parseHttpValue(input, this); } else if ("Content-Encoding".equalsIgnoreCase(name)) { return ContentEncoding.parseHttpValue(input, this); } else if ("Content-Length".equalsIgnoreCase(name)) { return ContentLength.parseHttpValue(input, this); } else if ("Content-Type".equalsIgnoreCase(name)) { return ContentType.parseHttpValue(input, this); } else if ("Expect".equalsIgnoreCase(name)) { return Expect.parseHttpValue(input, this); } else if ("Host".equalsIgnoreCase(name)) { return Host.parseHttpValue(input, this); } else if ("Max-Forwards".equalsIgnoreCase(name)) { return MaxForwards.parseHttpValue(input, this); } else if ("Origin".equalsIgnoreCase(name)) { return Origin.parseHttpValue(input, this); } else if ("Sec-WebSocket-Accept".equalsIgnoreCase(name)) { return SecWebSocketAccept.parseHttpValue(input, this); } else if ("Sec-WebSocket-Extensions".equalsIgnoreCase(name)) { return SecWebSocketExtensions.parseHttpValue(input, this); } else if ("Sec-WebSocket-Key".equalsIgnoreCase(name)) { return SecWebSocketKey.parseHttpValue(input, this); } else if ("Sec-WebSocket-Protocol".equalsIgnoreCase(name)) { return SecWebSocketProtocol.parseHttpValue(input, this); } else if ("Sec-WebSocket-Version".equalsIgnoreCase(name)) { return SecWebSocketVersion.parseHttpValue(input, this); } else if ("Server".equals(name)) { return Server.parseHttpValue(input, this); } else if ("Transfer-Encoding".equalsIgnoreCase(name)) { return TransferEncoding.parseHttpValue(input, this); } else if ("Upgrade".equalsIgnoreCase(name)) { return Upgrade.parseHttpValue(input, this); } else if ("User-Agent".equalsIgnoreCase(name)) { return UserAgent.parseHttpValue(input, this); } else { return RawHeader.parseHttpValue(input, this, name.toLowerCase(), name); } } public Parser<HttpChunkHeader> chunkHeaderParser() { return new HttpChunkHeaderParser(this); } public Parser<HttpChunkHeader> parseChunkHeader(Input input) { return HttpChunkHeaderParser.parse(input, this); } public HttpChunkHeader parseChunkHeaderString(String string) { final Input input = Unicode.stringInput(string); Parser<HttpChunkHeader> parser = parseChunkHeader(input); if (input.isCont() && !parser.isError()) { parser = Parser.error(Diagnostic.unexpected(input)); } return parser.bind(); } public Parser<HttpChunkTrailer> chunkTrailerParser() { return new HttpChunkTrailerParser(this); } public Parser<HttpChunkTrailer> parseChunkTrailer(Input input) { return HttpChunkTrailerParser.parse(input, this); } public HttpChunkTrailer parseChunkTrailerString(String string) { final Input input = Unicode.stringInput(string); Parser<HttpChunkTrailer> parser = parseChunkTrailer(input); if (input.isCont() && !parser.isError()) { parser = Parser.error(Diagnostic.unexpected(input)); } return parser.bind(); } public Parser<ChunkExtension> chunkExtensionParser() { return new ChunkExtensionParser(this); } public Parser<ChunkExtension> parseChunkExtension(Input input) { return ChunkExtensionParser.parse(input, this); } public ChunkExtension parseChunkExtensionString(String string) { final Input input = Unicode.stringInput(string); Parser<ChunkExtension> parser = parseChunkExtension(input); if (input.isCont() && !parser.isError()) { parser = Parser.error(Diagnostic.unexpected(input)); } return parser.bind(); } public Parser<HttpCharset> charsetParser() { return new HttpCharsetParser(this); } public Parser<HttpCharset> parseCharset(Input input) { return HttpCharsetParser.parse(input, this); } public HttpCharset parseCharsetString(String string) { final Input input = Unicode.stringInput(string); Parser<HttpCharset> parser = parseCharset(input); if (input.isCont() && !parser.isError()) { parser = Parser.error(Diagnostic.unexpected(input)); } return parser.bind(); } public Parser<LanguageRange> languageRangeParser() { return new LanguageRangeParser(this); } public Parser<LanguageRange> parseLanguageRange(Input input) { return LanguageRangeParser.parse(input, this); } public LanguageRange parseLanguageRangeString(String string) { final Input input = Unicode.stringInput(string); Parser<LanguageRange> parser = parseLanguageRange(input); if (input.isCont() && !parser.isError()) { parser = Parser.error(Diagnostic.unexpected(input)); } return parser.bind(); } public Parser<MediaRange> mediaRangeParser() { return new MediaRangeParser(this); } public Parser<MediaRange> parseMediaRange(Input input) { return MediaRangeParser.parse(input, this); } public MediaRange parseMediaRangeString(String string) { final Input input = Unicode.stringInput(string); Parser<MediaRange> parser = parseMediaRange(input); if (input.isCont() && !parser.isError()) { parser = Parser.error(Diagnostic.unexpected(input)); } return parser.bind(); } public Parser<MediaType> mediaTypeParser() { return new MediaTypeParser(this); } public Parser<MediaType> parseMediaType(Input input) { return MediaTypeParser.parse(input, this); } public MediaType parseMediaTypeString(String string) { final Input input = Unicode.stringInput(string); Parser<MediaType> parser = parseMediaType(input); if (input.isCont() && !parser.isError()) { parser = Parser.error(Diagnostic.unexpected(input)); } return parser.bind(); } public Parser<Product> productParser() { return new ProductParser(this); } public Parser<Product> parseProduct(Input input) { return ProductParser.parse(input, this); } public Product parseProductString(String string) { final Input input = Unicode.stringInput(string); Parser<Product> parser = parseProduct(input); if (input.isCont() && !parser.isError()) { parser = Parser.error(Diagnostic.unexpected(input)); } return parser.bind(); } public Parser<ContentCoding> contentCodingParser() { return new ContentCodingParser(this); } public Parser<ContentCoding> parseContentCoding(Input input) { return ContentCodingParser.parse(input, this); } public ContentCoding parseContentCodingString(String string) { final Input input = Unicode.stringInput(string); Parser<ContentCoding> parser = parseContentCoding(input); if (input.isCont() && !parser.isError()) { parser = Parser.error(Diagnostic.unexpected(input)); } return parser.bind(); } public Parser<TransferCoding> transferCodingParser() { return new TransferCodingParser(this); } public Parser<TransferCoding> parseTransferCoding(Input input) { return TransferCodingParser.parse(input, this); } public TransferCoding parseTransferCodingString(String string) { final Input input = Unicode.stringInput(string); Parser<TransferCoding> parser = parseTransferCoding(input); if (input.isCont() && !parser.isError()) { parser = Parser.error(Diagnostic.unexpected(input)); } return parser.bind(); } public Parser<UpgradeProtocol> upgradeProtocolParser() { return new UpgradeProtocolParser(this); } public Parser<UpgradeProtocol> parseUpgradeProtocol(Input input) { return UpgradeProtocolParser.parse(input, this); } public UpgradeProtocol parseUpgradeProtocolString(String string) { final Input input = Unicode.stringInput(string); Parser<UpgradeProtocol> parser = parseUpgradeProtocol(input); if (input.isCont() && !parser.isError()) { parser = Parser.error(Diagnostic.unexpected(input)); } return parser.bind(); } public Parser<WebSocketParam> webSocketParamParser() { return new WebSocketParamParser(this); } public Parser<WebSocketParam> parseWebSocketParam(Input input) { return WebSocketParamParser.parse(input, this); } public WebSocketParam parseWebSocketParamString(String string) { final Input input = Unicode.stringInput(string); Parser<WebSocketParam> parser = parseWebSocketParam(input); if (input.isCont() && !parser.isError()) { parser = Parser.error(Diagnostic.unexpected(input)); } return parser.bind(); } public Parser<WebSocketExtension> webSocketExtensionParser() { return new WebSocketExtensionParser(this); } public Parser<WebSocketExtension> parseWebSocketExtension(Input input) { return WebSocketExtensionParser.parse(input, this); } public WebSocketExtension parseWebSocketExtensionString(String string) { final Input input = Unicode.stringInput(string); Parser<WebSocketExtension> parser = parseWebSocketExtension(input); if (input.isCont() && !parser.isError()) { parser = Parser.error(Diagnostic.unexpected(input)); } return parser.bind(); } public Parser<Float> parseQValue(Input input) { return QValueParser.parse(input); } public Parser<Float> parseQValueRest(Input input) { return QValueParser.parseRest(input); } public Parser<String> parseComment(Input input) { return CommentParser.parse(input); } public Parser<FingerTrieSeq<String>> parseTokenList(Input input) { return TokenListParser.parse(input); } public Parser<HashTrieMap<String, String>> parseParamMap(Input input) { return ParamMapParser.parse(input); } public Parser<HashTrieMap<String, String>> parseParamMapRest(Input input) { return ParamMapParser.parseRest(input); } public Parser<HashTrieMap<String, String>> parseParamMapRest(StringBuilder key, Input input) { return ParamMapParser.parseRest(input, key); } public <T> Decoder<HttpMessage<T>> bodyDecoder(HttpMessage<?> message, Decoder<T> content, long length) { return new HttpBodyDecoder<T>(message, content, length); } public <T> Decoder<HttpMessage<T>> decodeBody(HttpMessage<?> message, Decoder<T> content, long length, InputBuffer input) { return HttpBodyDecoder.decode(input, message, content, length); } public <T> Decoder<HttpMessage<T>> chunkedDecoder(HttpMessage<?> message, Decoder<T> content) { return new HttpChunkedDecoder<T>(this, message, content); } public <T> Decoder<HttpMessage<T>> decodeChunked(HttpMessage<?> message, Decoder<T> content, InputBuffer input) { return HttpChunkedDecoder.decode(input, this, message, content); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpPart.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Output; import swim.codec.Utf8; import swim.codec.Writer; public abstract class HttpPart { public abstract Writer<?, ?> httpWriter(HttpWriter http); public Writer<?, ?> httpWriter() { return httpWriter(Http.standardWriter()); } public abstract Writer<?, ?> writeHttp(Output<?> output, HttpWriter http); public Writer<?, ?> writeHttp(Output<?> output) { return writeHttp(output, Http.standardWriter()); } public String toHttp() { final Output<String> output = Utf8.decodedString(); writeHttp(output); return output.bind(); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpRequest.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Debug; import swim.codec.Decoder; import swim.codec.Encoder; import swim.codec.Format; import swim.codec.Output; import swim.codec.OutputBuffer; import swim.codec.Writer; import swim.collections.FingerTrieSeq; import swim.uri.Uri; import swim.util.Murmur3; public final class HttpRequest<T> extends HttpMessage<T> implements Debug { final HttpMethod method; final Uri uri; final HttpVersion version; final FingerTrieSeq<HttpHeader> headers; final HttpEntity<T> entity; HttpRequest(HttpMethod method, Uri uri, HttpVersion version, FingerTrieSeq<HttpHeader> headers, HttpEntity<T> entity) { this.method = method; this.uri = uri; this.version = version; this.headers = headers; this.entity = entity; } HttpRequest(HttpMethod method, Uri uri, HttpVersion version, FingerTrieSeq<HttpHeader> headers) { this(method, uri, version, headers, HttpEntity.<T>empty()); } public HttpMethod method() { return this.method; } public HttpRequest<T> method(HttpMethod method) { return from(method, this.uri, this.version, this.headers, this.entity); } public Uri uri() { return this.uri; } public HttpRequest<T> uri(Uri uri) { return from(this.method, uri, this.version, this.headers, this.entity); } @Override public HttpVersion version() { return this.version; } public HttpRequest<T> version(HttpVersion version) { return from(this.method, this.uri, version, this.headers, this.entity); } @Override public FingerTrieSeq<HttpHeader> headers() { return this.headers; } @Override public HttpRequest<T> headers(FingerTrieSeq<HttpHeader> headers) { return from(this.method, this.uri, this.version, headers, this.entity); } @Override public HttpRequest<T> headers(HttpHeader... headers) { return headers(FingerTrieSeq.of(headers)); } @Override public HttpRequest<T> appendedHeaders(FingerTrieSeq<HttpHeader> newHeaders) { final FingerTrieSeq<HttpHeader> oldHeaders = this.headers; final FingerTrieSeq<HttpHeader> headers = oldHeaders.appended(newHeaders); if (oldHeaders != headers) { return from(this.method, this.uri, this.version, headers, this.entity); } else { return this; } } @Override public HttpRequest<T> appendedHeaders(HttpHeader... newHeaders) { return appendedHeaders(FingerTrieSeq.of(newHeaders)); } @Override public HttpRequest<T> appendedHeader(HttpHeader newHeader) { final FingerTrieSeq<HttpHeader> oldHeaders = this.headers; final FingerTrieSeq<HttpHeader> headers = oldHeaders.appended(newHeader); if (oldHeaders != headers) { return from(this.method, this.uri, this.version, headers, this.entity); } else { return this; } } @Override public HttpRequest<T> updatedHeaders(FingerTrieSeq<HttpHeader> newHeaders) { final FingerTrieSeq<HttpHeader> oldHeaders = this.headers; final FingerTrieSeq<HttpHeader> headers = updatedHeaders(oldHeaders, newHeaders); if (oldHeaders != headers) { return from(this.method, this.uri, this.version, headers, this.entity); } else { return this; } } @Override public HttpRequest<T> updatedHeaders(HttpHeader... newHeaders) { return updatedHeaders(FingerTrieSeq.of(newHeaders)); } @Override public HttpRequest<T> updatedHeader(HttpHeader newHeader) { final FingerTrieSeq<HttpHeader> oldHeaders = this.headers; final FingerTrieSeq<HttpHeader> headers = updatedHeaders(oldHeaders, newHeader); if (oldHeaders != headers) { return from(this.method, this.uri, this.version, headers, this.entity); } else { return this; } } @Override public HttpEntity<T> entity() { return this.entity; } @Override public <T2> HttpRequest<T2> entity(HttpEntity<T2> entity) { return from(this.method, this.uri, this.version, this.headers, entity); } @Override public <T2> HttpRequest<T2> content(HttpEntity<T2> entity) { final FingerTrieSeq<HttpHeader> headers = updatedHeaders(this.headers, entity.headers()); return from(this.method, this.uri, this.version, headers, entity); } @Override public HttpRequest<String> body(String content, MediaType mediaType) { return content(HttpBody.from(content, mediaType)); } @Override public HttpRequest<String> body(String content) { return content(HttpBody.from(content)); } @SuppressWarnings("unchecked") @Override public <T2> Decoder<HttpRequest<T2>> entityDecoder(Decoder<T2> contentDecoder) { return (Decoder<HttpRequest<T2>>) super.entityDecoder(contentDecoder); } @SuppressWarnings("unchecked") @Override public Encoder<?, HttpRequest<T>> httpEncoder(HttpWriter http) { return (Encoder<?, HttpRequest<T>>) super.httpEncoder(http); } @SuppressWarnings("unchecked") @Override public Encoder<?, HttpRequest<T>> httpEncoder() { return (Encoder<?, HttpRequest<T>>) super.httpEncoder(); } @SuppressWarnings("unchecked") @Override public Encoder<?, HttpRequest<T>> encodeHttp(OutputBuffer<?> output, HttpWriter http) { return (Encoder<?, HttpRequest<T>>) super.encodeHttp(output, http); } @SuppressWarnings("unchecked") @Override public Encoder<?, HttpRequest<T>> encodeHttp(OutputBuffer<?> output) { return (Encoder<?, HttpRequest<T>>) super.encodeHttp(output); } @Override public Writer<?, HttpRequest<T>> httpWriter(HttpWriter http) { return http.requestWriter(this); } @Override public Writer<?, HttpRequest<T>> httpWriter() { return httpWriter(Http.standardWriter()); } @Override public Writer<?, HttpRequest<T>> writeHttp(Output<?> output, HttpWriter http) { return http.writeRequest(this, output); } @Override public Writer<?, HttpRequest<T>> writeHttp(Output<?> output) { return writeHttp(output, Http.standardWriter()); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof HttpRequest<?>) { final HttpRequest<?> that = (HttpRequest<?>) other; return this.method.equals(that.method) && this.uri.equals(that.uri) && this.version.equals(that.version) && this.headers.equals(that.headers) && this.entity.equals(that.entity); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(HttpRequest.class); } return Murmur3.mash(Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(hashSeed, this.method.hashCode()), this.uri.hashCode()), this.version.hashCode()), this.headers.hashCode()), this.entity.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("HttpRequest").write('.').write("from").write('(') .debug(this.method).write(", ").debug(this.uri).write(", ").debug(this.version); for (HttpHeader header : this.headers) { output = output.write(", ").debug(header); } output = output.write(')'); if (this.entity.isDefined()) { output = output.write('.').write("entity").write('(').debug(this.entity).write(')'); } } @Override public String toString() { return Format.debug(this); } private static int hashSeed; public static <T> HttpRequest<T> from(HttpMethod method, Uri uri, HttpVersion version, FingerTrieSeq<HttpHeader> headers, HttpEntity<T> entity) { return new HttpRequest<T>(method, uri, version, headers, entity); } public static <T> HttpRequest<T> from(HttpMethod method, Uri uri, HttpVersion version, FingerTrieSeq<HttpHeader> headers) { return new HttpRequest<T>(method, uri, version, headers); } public static <T> HttpRequest<T> from(HttpMethod method, Uri uri, HttpVersion version, HttpHeader... headers) { return new HttpRequest<T>(method, uri, version, FingerTrieSeq.of(headers)); } public static <T> HttpRequest<T> from(HttpMethod method, Uri uri, HttpVersion version) { return new HttpRequest<T>(method, uri, version, FingerTrieSeq.<HttpHeader>empty()); } public static <T> HttpRequest<T> get(Uri uri, FingerTrieSeq<HttpHeader> headers) { return new HttpRequest<T>(HttpMethod.GET, uri, HttpVersion.HTTP_1_1, headers); } public static <T> HttpRequest<T> get(Uri uri, HttpHeader... headers) { return new HttpRequest<T>(HttpMethod.GET, uri, HttpVersion.HTTP_1_1, FingerTrieSeq.of(headers)); } public static <T> HttpRequest<T> head(Uri uri, FingerTrieSeq<HttpHeader> headers) { return new HttpRequest<T>(HttpMethod.HEAD, uri, HttpVersion.HTTP_1_1, headers); } public static <T> HttpRequest<T> head(Uri uri, HttpHeader... headers) { return new HttpRequest<T>(HttpMethod.HEAD, uri, HttpVersion.HTTP_1_1, FingerTrieSeq.of(headers)); } public static <T> HttpRequest<T> post(Uri uri, FingerTrieSeq<HttpHeader> headers) { return new HttpRequest<T>(HttpMethod.POST, uri, HttpVersion.HTTP_1_1, headers); } public static <T> HttpRequest<T> post(Uri uri, HttpHeader... headers) { return new HttpRequest<T>(HttpMethod.POST, uri, HttpVersion.HTTP_1_1, FingerTrieSeq.of(headers)); } public static <T> HttpRequest<T> put(Uri uri, FingerTrieSeq<HttpHeader> headers) { return new HttpRequest<T>(HttpMethod.PUT, uri, HttpVersion.HTTP_1_1, headers); } public static <T> HttpRequest<T> put(Uri uri, HttpHeader... headers) { return new HttpRequest<T>(HttpMethod.PUT, uri, HttpVersion.HTTP_1_1, FingerTrieSeq.of(headers)); } public static <T> HttpRequest<T> delete(Uri uri, FingerTrieSeq<HttpHeader> headers) { return new HttpRequest<T>(HttpMethod.DELETE, uri, HttpVersion.HTTP_1_1, headers); } public static <T> HttpRequest<T> delete(Uri uri, HttpHeader... headers) { return new HttpRequest<T>(HttpMethod.DELETE, uri, HttpVersion.HTTP_1_1, FingerTrieSeq.of(headers)); } public static <T> HttpRequest<T> connect(Uri uri, FingerTrieSeq<HttpHeader> headers) { return new HttpRequest<T>(HttpMethod.CONNECT, uri, HttpVersion.HTTP_1_1, headers); } public static <T> HttpRequest<T> connect(Uri uri, HttpHeader... headers) { return new HttpRequest<T>(HttpMethod.CONNECT, uri, HttpVersion.HTTP_1_1, FingerTrieSeq.of(headers)); } public static <T> HttpRequest<T> options(Uri uri, FingerTrieSeq<HttpHeader> headers) { return new HttpRequest<T>(HttpMethod.OPTIONS, uri, HttpVersion.HTTP_1_1, headers); } public static <T> HttpRequest<T> options(Uri uri, HttpHeader... headers) { return new HttpRequest<T>(HttpMethod.OPTIONS, uri, HttpVersion.HTTP_1_1, FingerTrieSeq.of(headers)); } public static <T> HttpRequest<T> trace(Uri uri, FingerTrieSeq<HttpHeader> headers) { return new HttpRequest<T>(HttpMethod.TRACE, uri, HttpVersion.HTTP_1_1, headers); } public static <T> HttpRequest<T> trace(Uri uri, HttpHeader... headers) { return new HttpRequest<T>(HttpMethod.TRACE, uri, HttpVersion.HTTP_1_1, FingerTrieSeq.of(headers)); } public static <T> HttpRequest<T> parseHttp(String string) { return Http.standardParser().parseRequestString(string); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpRequestParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.codec.ParserException; import swim.collections.FingerTrieSeq; import swim.uri.Uri; import swim.util.Builder; final class HttpRequestParser<T> extends Parser<HttpRequest<T>> { final HttpParser http; final Parser<HttpMethod> method; final StringBuilder uri; final Parser<HttpVersion> version; final Parser<? extends HttpHeader> header; final Builder<HttpHeader, FingerTrieSeq<HttpHeader>> headers; final int step; HttpRequestParser(HttpParser http, Parser<HttpMethod> method, StringBuilder uri, Parser<HttpVersion> version, Parser<? extends HttpHeader> header, Builder<HttpHeader, FingerTrieSeq<HttpHeader>> headers, int step) { this.http = http; this.method = method; this.uri = uri; this.version = version; this.header = header; this.headers = headers; this.step = step; } HttpRequestParser(HttpParser http) { this(http, null, null, null, null, null, 1); } @Override public Parser<HttpRequest<T>> feed(Input input) { return parse(input, this.http, this.method, this.uri, this.version, this.header, this.headers, this.step); } static <T> Parser<HttpRequest<T>> parse(Input input, HttpParser http, Parser<HttpMethod> method, StringBuilder uri, Parser<HttpVersion> version, Parser<? extends HttpHeader> header, Builder<HttpHeader, FingerTrieSeq<HttpHeader>> headers, int step) { int c = 0; if (step == 1) { if (method == null) { if (input.isDone()) { return done(); } method = http.parseMethod(input); } else { method = method.feed(input); } if (method.isDone()) { step = 2; } else if (method.isError()) { return method.asError(); } } if (step == 2) { if (input.isCont() && input.head() == ' ') { input = input.step(); step = 3; } else if (!input.isEmpty()) { return error(Diagnostic.expected("space", input)); } } if (step == 3) { if (uri == null) { uri = new StringBuilder(); } while (input.isCont()) { c = input.head(); if (c != ' ') { input = input.step(); uri.appendCodePoint(c); } else { break; } } if (!input.isEmpty()) { step = 4; } } if (step == 4) { if (input.isCont() && input.head() == ' ') { input = input.step(); step = 5; } else if (!input.isEmpty()) { return error(Diagnostic.expected("space", input)); } } if (step == 5) { if (version == null) { version = http.parseVersion(input); } else { version = version.feed(input); } if (version.isDone()) { step = 6; } else if (version.isError()) { return version.asError(); } } if (step == 6) { if (input.isCont() && input.head() == '\r') { input = input.step(); step = 7; } else if (!input.isEmpty()) { return error(Diagnostic.expected("carriage return", input)); } } if (step == 7) { if (input.isCont() && input.head() == '\n') { input = input.step(); step = 8; } else if (!input.isEmpty()) { return error(Diagnostic.expected("line feed", input)); } } do { if (step == 8) { if (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { step = 9; } else if (Http.isSpace(c)) { return error(Diagnostic.message("unsupported header line extension", input)); } else if (c == '\r') { input = input.step(); step = 12; break; } else { return error(Diagnostic.expected("HTTP header", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("HTTP header", input)); } } if (step == 9) { if (header == null) { header = http.parseHeader(input); } else { header = header.feed(input); } if (header.isDone()) { step = 10; } else if (header.isError()) { return header.asError(); } } if (step == 10) { if (input.isCont() && input.head() == '\r') { input = input.step(); step = 11; } else if (!input.isEmpty()) { return error(Diagnostic.expected("carriage return", input)); } } if (step == 11) { if (input.isCont() && input.head() == '\n') { if (headers == null) { headers = FingerTrieSeq.builder(); } headers.add(header.bind()); header = null; input = input.step(); step = 8; continue; } else if (!input.isEmpty()) { return error(Diagnostic.expected("line feed", input)); } } break; } while (true); if (step == 12) { if (input.isCont() && input.head() == '\n') { input = input.step(); final Uri requestUri; try { requestUri = Uri.parse(uri.toString()); } catch (ParserException cause) { return error(cause); } if (headers == null) { final HttpRequest<T> request = http.request(method.bind(), requestUri, version.bind(), FingerTrieSeq.<HttpHeader>empty()); return done(request); } else { final HttpRequest<T> request = http.request(method.bind(), requestUri, version.bind(), headers.bind()); return done(request); } } else if (!input.isEmpty()) { return error(Diagnostic.expected("line feed", input)); } } if (input.isError()) { return error(input.trap()); } return new HttpRequestParser<T>(http, method, uri, version, header, headers, step); } static <T> Parser<HttpRequest<T>> parse(Input input, HttpParser http) { return parse(input, http, null, null, null, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpRequestWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import java.util.Iterator; import swim.codec.Output; import swim.codec.Unicode; import swim.codec.Writer; import swim.codec.WriterException; final class HttpRequestWriter<T> extends Writer<Object, HttpRequest<T>> { final HttpWriter http; final HttpRequest<T> request; final Iterator<HttpHeader> headers; final Writer<?, ?> part; final int step; HttpRequestWriter(HttpWriter http, HttpRequest<T> request, Iterator<HttpHeader> headers, Writer<?, ?> part, int step) { this.http = http; this.request = request; this.headers = headers; this.part = part; this.step = step; } HttpRequestWriter(HttpWriter http, HttpRequest<T> request) { this(http, request, null, null, 1); } @Override public Writer<Object, HttpRequest<T>> pull(Output<?> output) { return write(output, this.http, this.request, this.headers, this.part, this.step); } static <T> Writer<Object, HttpRequest<T>> write(Output<?> output, HttpWriter http, HttpRequest<T> request, Iterator<HttpHeader> headers, Writer<?, ?> part, int step) { if (step == 1) { if (part == null) { part = request.method.writeHttp(output, http); } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 2; } else if (part.isError()) { return part.asError(); } } if (step == 2 && output.isCont()) { output = output.write(' '); step = 3; } if (step == 3) { if (part == null) { part = Unicode.writeString(request.uri.toString(), output); } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 4; } else if (part.isError()) { return part.asError(); } } if (step == 4 && output.isCont()) { output = output.write(' '); step = 5; } if (step == 5) { if (part == null) { part = request.version.writeHttp(output, http); } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 6; } else if (part.isError()) { return part.asError(); } } if (step == 6 && output.isCont()) { output = output.write('\r'); step = 7; } if (step == 7 && output.isCont()) { output = output.write('\n'); step = 8; } do { if (step == 8) { if (part == null) { if (headers == null) { headers = request.headers.iterator(); } if (!headers.hasNext()) { step = 11; break; } else { part = headers.next().writeHttp(output, http); } } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 9; } else if (part.isError()) { return part.asError(); } } if (step == 9 && output.isCont()) { output = output.write('\r'); step = 10; } if (step == 10 && output.isCont()) { output = output.write('\n'); step = 8; continue; } break; } while (true); if (step == 11 && output.isCont()) { output = output.write('\r'); step = 12; } if (step == 12 && output.isCont()) { output = output.write('\n'); return done(request); } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new HttpRequestWriter<T>(http, request, headers, part, step); } static <T> Writer<Object, HttpRequest<T>> write(Output<?> output, HttpWriter http, HttpRequest<T> request) { return write(output, http, request, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpResponse.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Debug; import swim.codec.Decoder; import swim.codec.Encoder; import swim.codec.Format; import swim.codec.Output; import swim.codec.OutputBuffer; import swim.codec.Writer; import swim.collections.FingerTrieSeq; import swim.util.Murmur3; public final class HttpResponse<T> extends HttpMessage<T> implements Debug { final HttpVersion version; final HttpStatus status; final FingerTrieSeq<HttpHeader> headers; final HttpEntity<T> entity; HttpResponse(HttpVersion version, HttpStatus status, FingerTrieSeq<HttpHeader> headers, HttpEntity<T> entity) { this.version = version; this.status = status; this.headers = headers; this.entity = entity; } HttpResponse(HttpVersion version, HttpStatus status, FingerTrieSeq<HttpHeader> headers) { this(version, status, headers, HttpEntity.<T>empty()); } @Override public HttpVersion version() { return this.version; } public HttpResponse<T> version(HttpVersion version) { return from(version, this.status, this.headers, this.entity); } public HttpStatus status() { return this.status; } public HttpResponse<T> status(HttpStatus status) { return from(this.version, status, this.headers, this.entity); } @Override public FingerTrieSeq<HttpHeader> headers() { return this.headers; } @Override public HttpResponse<T> headers(FingerTrieSeq<HttpHeader> headers) { return from(this.version, this.status, headers, this.entity); } @Override public HttpResponse<T> headers(HttpHeader... headers) { return headers(FingerTrieSeq.of(headers)); } @Override public HttpResponse<T> appendedHeaders(FingerTrieSeq<HttpHeader> newHeaders) { final FingerTrieSeq<HttpHeader> oldHeaders = this.headers; final FingerTrieSeq<HttpHeader> headers = oldHeaders.appended(newHeaders); if (oldHeaders != headers) { return from(this.version, this.status, headers, this.entity); } else { return this; } } @Override public HttpResponse<T> appendedHeaders(HttpHeader... newHeaders) { return appendedHeaders(FingerTrieSeq.of(newHeaders)); } @Override public HttpResponse<T> appendedHeader(HttpHeader newHeader) { final FingerTrieSeq<HttpHeader> oldHeaders = this.headers; final FingerTrieSeq<HttpHeader> headers = oldHeaders.appended(newHeader); if (oldHeaders != headers) { return from(this.version, this.status, headers, this.entity); } else { return this; } } @Override public HttpResponse<T> updatedHeaders(FingerTrieSeq<HttpHeader> newHeaders) { final FingerTrieSeq<HttpHeader> oldHeaders = this.headers; final FingerTrieSeq<HttpHeader> headers = updatedHeaders(oldHeaders, newHeaders); if (oldHeaders != headers) { return from(this.version, this.status, headers, this.entity); } else { return this; } } @Override public HttpResponse<T> updatedHeaders(HttpHeader... newHeaders) { return updatedHeaders(FingerTrieSeq.of(newHeaders)); } @Override public HttpResponse<T> updatedHeader(HttpHeader newHeader) { final FingerTrieSeq<HttpHeader> oldHeaders = this.headers; final FingerTrieSeq<HttpHeader> headers = updatedHeaders(oldHeaders, newHeader); if (oldHeaders != headers) { return from(this.version, this.status, headers, this.entity); } else { return this; } } @Override public HttpEntity<T> entity() { return this.entity; } @Override public <T2> HttpResponse<T2> entity(HttpEntity<T2> entity) { return from(this.version, this.status, this.headers, entity); } @Override public <T2> HttpResponse<T2> content(HttpEntity<T2> entity) { final FingerTrieSeq<HttpHeader> headers = updatedHeaders(this.headers, entity.headers()); return from(this.version, this.status, headers, entity); } @Override public HttpResponse<String> body(String content, MediaType mediaType) { return content(HttpBody.from(content, mediaType)); } @Override public HttpResponse<String> body(String content) { return content(HttpBody.from(content)); } @SuppressWarnings("unchecked") @Override public <T2> Decoder<HttpResponse<T2>> entityDecoder(Decoder<T2> contentDecoder) { return (Decoder<HttpResponse<T2>>) super.entityDecoder(contentDecoder); } @SuppressWarnings("unchecked") @Override public Encoder<?, HttpResponse<T>> httpEncoder(HttpWriter http) { return (Encoder<?, HttpResponse<T>>) super.httpEncoder(http); } @SuppressWarnings("unchecked") @Override public Encoder<?, HttpResponse<T>> httpEncoder() { return (Encoder<?, HttpResponse<T>>) super.httpEncoder(); } @SuppressWarnings("unchecked") @Override public Encoder<?, HttpResponse<T>> encodeHttp(OutputBuffer<?> output, HttpWriter http) { return (Encoder<?, HttpResponse<T>>) super.encodeHttp(output, http); } @SuppressWarnings("unchecked") @Override public Encoder<?, HttpResponse<T>> encodeHttp(OutputBuffer<?> output) { return (Encoder<?, HttpResponse<T>>) super.encodeHttp(output); } @Override public Writer<?, HttpResponse<T>> httpWriter(HttpWriter http) { return http.responseWriter(this); } @Override public Writer<?, HttpResponse<T>> httpWriter() { return httpWriter(Http.standardWriter()); } @Override public Writer<?, HttpResponse<T>> writeHttp(Output<?> output, HttpWriter http) { return http.writeResponse(this, output); } @Override public Writer<?, HttpResponse<T>> writeHttp(Output<?> output) { return writeHttp(output, Http.standardWriter()); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof HttpResponse<?>) { final HttpResponse<?> that = (HttpResponse<?>) other; return this.version.equals(that.version) && this.status.equals(that.status) && this.headers.equals(that.headers) && this.entity.equals(that.entity); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(HttpResponse.class); } return Murmur3.mash(Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix(hashSeed, this.version.hashCode()), this.status.hashCode()), this.headers.hashCode()), this.entity.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("HttpResponse").write('.').write("from").write('(') .debug(this.version).write(", ").debug(this.status); for (HttpHeader header : this.headers) { output = output.write(", ").debug(header); } output = output.write(')'); if (this.entity.isDefined()) { output = output.write('.').write("entity").write('(').debug(this.entity).write(')'); } } @Override public String toString() { return Format.debug(this); } private static int hashSeed; public static <T> HttpResponse<T> from(HttpVersion version, HttpStatus status, FingerTrieSeq<HttpHeader> headers, HttpEntity<T> entity) { return new HttpResponse<T>(version, status, headers, entity); } public static <T> HttpResponse<T> from(HttpVersion version, HttpStatus status, FingerTrieSeq<HttpHeader> headers) { return new HttpResponse<T>(version, status, headers); } public static <T> HttpResponse<T> from(HttpVersion version, HttpStatus status, HttpHeader... headers) { return new HttpResponse<T>(version, status, FingerTrieSeq.of(headers)); } public static <T> HttpResponse<T> from(HttpVersion version, HttpStatus status) { return new HttpResponse<T>(version, status, FingerTrieSeq.<HttpHeader>empty()); } public static <T> HttpResponse<T> from(HttpStatus status, FingerTrieSeq<HttpHeader> headers) { return new HttpResponse<T>(HttpVersion.HTTP_1_1, status, headers); } public static <T> HttpResponse<T> from(HttpStatus status, HttpHeader... headers) { return new HttpResponse<T>(HttpVersion.HTTP_1_1, status, FingerTrieSeq.of(headers)); } public static <T> HttpResponse<T> from(HttpStatus status) { return new HttpResponse<T>(HttpVersion.HTTP_1_1, status, FingerTrieSeq.<HttpHeader>empty()); } public static <T> HttpResponse<T> parseHttp(String string) { return Http.standardParser().parseResponseString(string); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpResponseParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.collections.FingerTrieSeq; import swim.util.Builder; final class HttpResponseParser<T> extends Parser<HttpResponse<T>> { final HttpParser http; final Parser<HttpVersion> version; final Parser<HttpStatus> status; final Parser<? extends HttpHeader> header; final Builder<HttpHeader, FingerTrieSeq<HttpHeader>> headers; final int step; HttpResponseParser(HttpParser http, Parser<HttpVersion> version, Parser<HttpStatus> status, Parser<? extends HttpHeader> header, Builder<HttpHeader, FingerTrieSeq<HttpHeader>> headers, int step) { this.http = http; this.version = version; this.status = status; this.header = header; this.headers = headers; this.step = step; } HttpResponseParser(HttpParser http) { this(http, null, null, null, null, 1); } @Override public Parser<HttpResponse<T>> feed(Input input) { return parse(input, this.http, this.version, this.status, this.header, this.headers, this.step); } static <T> Parser<HttpResponse<T>> parse(Input input, HttpParser http, Parser<HttpVersion> version, Parser<HttpStatus> status, Parser<? extends HttpHeader> header, Builder<HttpHeader, FingerTrieSeq<HttpHeader>> headers, int step) { int c = 0; if (step == 1) { if (version == null) { if (input.isDone()) { return done(); } version = http.parseVersion(input); } else { version = version.feed(input); } if (version.isDone()) { step = 2; } else if (version.isError()) { return version.asError(); } } if (step == 2) { if (input.isCont() && input.head() == ' ') { input = input.step(); step = 3; } else if (!input.isEmpty()) { return error(Diagnostic.expected("space", input)); } } if (step == 3) { if (status == null) { status = http.parseStatus(input); } else { status = status.feed(input); } if (status.isDone()) { step = 4; } else if (status.isError()) { return status.asError(); } } if (step == 4) { if (input.isCont() && input.head() == '\r') { input = input.step(); step = 5; } else if (!input.isEmpty()) { return error(Diagnostic.expected("carriage return", input)); } } if (step == 5) { if (input.isCont() && input.head() == '\n') { input = input.step(); step = 6; } else if (!input.isEmpty()) { return error(Diagnostic.expected("line feed", input)); } } do { if (step == 6) { if (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { step = 7; } else if (Http.isSpace(c)) { return error(Diagnostic.message("unsupported header line extension", input)); } else if (c == '\r') { input = input.step(); step = 10; } else { return error(Diagnostic.expected("HTTP header", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("HTTP header", input)); } } if (step == 7) { if (header == null) { header = http.parseHeader(input); } else { header = header.feed(input); } if (header.isDone()) { step = 8; } else if (header.isError()) { return header.asError(); } } if (step == 8) { if (input.isCont() && input.head() == '\r') { input = input.step(); step = 9; } else if (!input.isEmpty()) { return error(Diagnostic.expected("carriage return", input)); } } if (step == 9) { if (input.isCont() && input.head() == '\n') { if (headers == null) { headers = FingerTrieSeq.builder(); } headers.add(header.bind()); header = null; input = input.step(); step = 6; continue; } else if (!input.isEmpty()) { return error(Diagnostic.expected("line feed", input)); } } break; } while (true); if (step == 10) { if (input.isCont() && input.head() == '\n') { input = input.step(); if (headers == null) { final HttpResponse<T> response = http.response(version.bind(), status.bind(), FingerTrieSeq.<HttpHeader>empty()); return done(response); } else { final HttpResponse<T> response = http.response(version.bind(), status.bind(), headers.bind()); return done(response); } } else if (!input.isEmpty()) { return error(Diagnostic.expected("line feed", input)); } } if (input.isError()) { return error(input.trap()); } return new HttpResponseParser<T>(http, version, status, header, headers, step); } static <T> Parser<HttpResponse<T>> parse(Input input, HttpParser http) { return parse(input, http, null, null, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpResponseWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import java.util.Iterator; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class HttpResponseWriter<T> extends Writer<Object, HttpResponse<T>> { final HttpWriter http; final HttpResponse<T> response; final Iterator<HttpHeader> headers; final Writer<?, ?> part; final int step; HttpResponseWriter(HttpWriter http, HttpResponse<T> response, Iterator<HttpHeader> headers, Writer<?, ?> part, int step) { this.http = http; this.response = response; this.headers = headers; this.part = part; this.step = step; } HttpResponseWriter(HttpWriter http, HttpResponse<T> response) { this(http, response, null, null, 1); } @Override public Writer<Object, HttpResponse<T>> pull(Output<?> output) { return write(output, this.http, this.response, this.headers, this.part, this.step); } static <T> Writer<Object, HttpResponse<T>> write(Output<?> output, HttpWriter http, HttpResponse<T> response, Iterator<HttpHeader> headers, Writer<?, ?> part, int step) { if (step == 1) { if (part == null) { part = response.version.writeHttp(output, http); } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 2; } else if (part.isError()) { return part.asError(); } } if (step == 2 && output.isCont()) { output = output.write(' '); step = 3; } if (step == 3) { if (part == null) { part = response.status.writeHttp(output, http); } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 4; } else if (part.isError()) { return part.asError(); } } if (step == 4 && output.isCont()) { output = output.write('\r'); step = 5; } if (step == 5 && output.isCont()) { output = output.write('\n'); step = 6; } do { if (step == 6) { if (part == null) { if (headers == null) { headers = response.headers.iterator(); } if (!headers.hasNext()) { step = 9; break; } else { part = headers.next().writeHttp(output, http); } } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 7; } else if (part.isError()) { return part.asError(); } } if (step == 7 && output.isCont()) { output = output.write('\r'); step = 8; } if (step == 8 && output.isCont()) { output = output.write('\n'); step = 6; continue; } break; } while (true); if (step == 9 && output.isCont()) { output = output.write('\r'); step = 10; } if (step == 10 && output.isCont()) { output = output.write('\n'); return done(response); } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new HttpResponseWriter<T>(http, response, headers, part, step); } static <T> Writer<Object, HttpResponse<T>> write(Output<?> output, HttpWriter http, HttpResponse<T> response) { return write(output, http, response, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpStatus.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Debug; import swim.codec.Format; import swim.codec.Output; import swim.codec.Writer; import swim.util.Murmur3; public final class HttpStatus extends HttpPart implements Debug { final int code; final String phrase; HttpStatus(int code, String phrase) { this.code = code; this.phrase = phrase; } public int code() { return this.code; } public String phrase() { return this.phrase; } @Override public Writer<?, ?> httpWriter(HttpWriter http) { return http.statusWriter(this.code, this.phrase); } @Override public Writer<?, ?> writeHttp(Output<?> output, HttpWriter http) { return http.writeStatus(this.code, this.phrase, output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof HttpStatus) { final HttpStatus that = (HttpStatus) other; return this.code == that.code && this.phrase.equals(that.phrase); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(HttpStatus.class); } return Murmur3.mash(Murmur3.mix(Murmur3.mix(hashSeed, this.code), this.phrase.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("HttpStatus").write('.').write("from").write('(') .debug(this.code).write(", ").debug(this.phrase).write(')'); } @Override public String toString() { return Format.debug(this); } private static int hashSeed; public static final HttpStatus CONTINUE = new HttpStatus(100, "Continue"); public static final HttpStatus SWITCHING_PROTOCOLS = new HttpStatus(101, "Switching Protocols"); public static final HttpStatus OK = new HttpStatus(200, "OK"); public static final HttpStatus CREATED = new HttpStatus(201, "Created"); public static final HttpStatus ACCEPTED = new HttpStatus(202, "Accepted"); public static final HttpStatus NON_AUTHORITATIVE_INFORMATION = new HttpStatus(203, "Non-Authoritative Information"); public static final HttpStatus NO_CONTENT = new HttpStatus(204, "No Content"); public static final HttpStatus RESET_CONTENT = new HttpStatus(205, "Reset Content"); public static final HttpStatus PARTIAL_CONTENT = new HttpStatus(206, "Partial Content"); public static final HttpStatus MULTIPLE_CHOICES = new HttpStatus(300, "Multiple Choices"); public static final HttpStatus MOVED_PERMANENTLY = new HttpStatus(301, "Moved Permanently"); public static final HttpStatus FOUND = new HttpStatus(302, "Found"); public static final HttpStatus SEE_OTHER = new HttpStatus(303, "See Other"); public static final HttpStatus NOT_MODIFIED = new HttpStatus(304, "Not Modified"); public static final HttpStatus USE_PROXY = new HttpStatus(305, "Use Proxy"); public static final HttpStatus TEMPORARY_REDIRECT = new HttpStatus(307, "Temporary Redirect"); public static final HttpStatus BAD_REQUEST = new HttpStatus(400, "Bad Request"); public static final HttpStatus UNAUTHORIZED = new HttpStatus(401, "Unauthorized"); public static final HttpStatus PAYMENT_REQUIRED = new HttpStatus(402, "Payment Required"); public static final HttpStatus FORBIDDEN = new HttpStatus(403, "Forbidden"); public static final HttpStatus NOT_FOUND = new HttpStatus(404, "Not Found"); public static final HttpStatus METHOD_NOT_ALLOWED = new HttpStatus(405, "Method Not Allowed"); public static final HttpStatus NOT_ACCEPTABLE = new HttpStatus(406, "Not Acceptable"); public static final HttpStatus PROXY_AUTHENTICATION_REQUIRED = new HttpStatus(407, "Proxy Authentication Required"); public static final HttpStatus REQUEST_TIMEOUT = new HttpStatus(408, "Request Timeout"); public static final HttpStatus CONFLICT = new HttpStatus(409, "Conflict"); public static final HttpStatus GONE = new HttpStatus(410, "Gone"); public static final HttpStatus LENGTH_REQUIRED = new HttpStatus(411, "Length Required"); public static final HttpStatus PRECONDITION_FAILED = new HttpStatus(412, "Precondition Failed"); public static final HttpStatus PAYLOAD_TOO_LARGE = new HttpStatus(413, "Payload Too Large"); public static final HttpStatus URI_TOO_LONG = new HttpStatus(414, "URI Too Long"); public static final HttpStatus UNSUPPORTED_MEDIA_TYPE = new HttpStatus(415, "Unsupported Media Type"); public static final HttpStatus RANGE_NOT_SATISFIABLE = new HttpStatus(416, "Range Not Satisfiable"); public static final HttpStatus EXPECTATION_FAILED = new HttpStatus(417, "Expectation Failed"); public static final HttpStatus UPGRADE_REQUIRED = new HttpStatus(426, "Upgrade Required"); public static final HttpStatus INTERNAL_SERVER_ERROR = new HttpStatus(500, "Internal Server Error"); public static final HttpStatus NOT_IMPLEMENTED = new HttpStatus(501, "Not Implemented"); public static final HttpStatus BAD_GATEWAY = new HttpStatus(502, "Bad Gateway"); public static final HttpStatus SERVICE_UNAVAILABLE = new HttpStatus(503, "Service Unavailable"); public static final HttpStatus GATEWAY_TIMEOUT = new HttpStatus(504, "Gateway Timeout"); public static final HttpStatus HTTP_VERSION_NOT_SUPPORTED = new HttpStatus(505, "HTTP Version Not Supported"); public static HttpStatus from(int code) { switch (code) { case 100: return CONTINUE; case 101: return SWITCHING_PROTOCOLS; case 200: return OK; case 201: return CREATED; case 202: return ACCEPTED; case 203: return NON_AUTHORITATIVE_INFORMATION; case 204: return NO_CONTENT; case 205: return RESET_CONTENT; case 206: return PARTIAL_CONTENT; case 300: return MULTIPLE_CHOICES; case 301: return MOVED_PERMANENTLY; case 302: return FOUND; case 303: return SEE_OTHER; case 304: return NOT_MODIFIED; case 305: return USE_PROXY; case 307: return TEMPORARY_REDIRECT; case 400: return BAD_REQUEST; case 401: return UNAUTHORIZED; case 402: return PAYMENT_REQUIRED; case 403: return FORBIDDEN; case 404: return NOT_FOUND; case 405: return METHOD_NOT_ALLOWED; case 406: return NOT_ACCEPTABLE; case 407: return PROXY_AUTHENTICATION_REQUIRED; case 408: return REQUEST_TIMEOUT; case 409: return CONFLICT; case 410: return GONE; case 411: return LENGTH_REQUIRED; case 412: return PRECONDITION_FAILED; case 413: return PAYLOAD_TOO_LARGE; case 414: return URI_TOO_LONG; case 415: return UNSUPPORTED_MEDIA_TYPE; case 416: return RANGE_NOT_SATISFIABLE; case 417: return EXPECTATION_FAILED; case 426: return UPGRADE_REQUIRED; case 500: return INTERNAL_SERVER_ERROR; case 501: return NOT_IMPLEMENTED; case 502: return BAD_GATEWAY; case 503: return SERVICE_UNAVAILABLE; case 504: return GATEWAY_TIMEOUT; case 505: return HTTP_VERSION_NOT_SUPPORTED; default: return new HttpStatus(code, ""); } } public static HttpStatus from(int code, String phrase) { if (code == 100 && phrase.equals("Continue")) { return CONTINUE; } else if (code == 101 && phrase.equals("Switching Protocols")) { return SWITCHING_PROTOCOLS; } else if (code == 200 && phrase.equals("OK")) { return OK; } else if (code == 201 && phrase.equals("Created")) { return CREATED; } else if (code == 202 && phrase.equals("Accepted")) { return ACCEPTED; } else if (code == 203 && phrase.equals("Non-Authoritative Information")) { return NON_AUTHORITATIVE_INFORMATION; } else if (code == 204 && phrase.equals("No Content")) { return NO_CONTENT; } else if (code == 205 && phrase.equals("Reset Content")) { return RESET_CONTENT; } else if (code == 206 && phrase.equals("Partial Content")) { return PARTIAL_CONTENT; } else if (code == 300 && phrase.equals("Multiple Choices")) { return MULTIPLE_CHOICES; } else if (code == 301 && phrase.equals("Moved Permanently")) { return MOVED_PERMANENTLY; } else if (code == 302 && phrase.equals("Found")) { return FOUND; } else if (code == 303 && phrase.equals("See Other")) { return SEE_OTHER; } else if (code == 304 && phrase.equals("Not Modified")) { return NOT_MODIFIED; } else if (code == 305 && phrase.equals("Use Proxy")) { return USE_PROXY; } else if (code == 307 && phrase.equals("Temporary Redirect")) { return TEMPORARY_REDIRECT; } else if (code == 400 && phrase.equals("Bad Request")) { return BAD_REQUEST; } else if (code == 401 && phrase.equals("Unauthorized")) { return UNAUTHORIZED; } else if (code == 402 && phrase.equals("Payment Required")) { return PAYMENT_REQUIRED; } else if (code == 403 && phrase.equals("Forbidden")) { return FORBIDDEN; } else if (code == 404 && phrase.equals("Not Found")) { return NOT_FOUND; } else if (code == 405 && phrase.equals("Method Not Allowed")) { return METHOD_NOT_ALLOWED; } else if (code == 406 && phrase.equals("Not Acceptable")) { return NOT_ACCEPTABLE; } else if (code == 407 && phrase.equals("Proxy Authentication Required")) { return PROXY_AUTHENTICATION_REQUIRED; } else if (code == 408 && phrase.equals("Request Timeout")) { return REQUEST_TIMEOUT; } else if (code == 409 && phrase.equals("Conflict")) { return CONFLICT; } else if (code == 410 && phrase.equals("Gone")) { return GONE; } else if (code == 411 && phrase.equals("Length Required")) { return LENGTH_REQUIRED; } else if (code == 412 && phrase.equals("Precondition Failed")) { return PRECONDITION_FAILED; } else if (code == 413 && phrase.equals("Payload Too Large")) { return PAYLOAD_TOO_LARGE; } else if (code == 414 && phrase.equals("URI Too Long")) { return URI_TOO_LONG; } else if (code == 415 && phrase.equals("Unsupported Media Type")) { return UNSUPPORTED_MEDIA_TYPE; } else if (code == 416 && phrase.equals("Range Not Satisfiable")) { return RANGE_NOT_SATISFIABLE; } else if (code == 417 && phrase.equals("Expectation Failed")) { return EXPECTATION_FAILED; } else if (code == 426 && phrase.equals("Upgrade Required")) { return UPGRADE_REQUIRED; } else if (code == 500 && phrase.equals("Internal Server Error")) { return INTERNAL_SERVER_ERROR; } else if (code == 501 && phrase.equals("Not Implemented")) { return NOT_IMPLEMENTED; } else if (code == 502 && phrase.equals("Bad Gateway")) { return BAD_GATEWAY; } else if (code == 503 && phrase.equals("Service Unavailable")) { return SERVICE_UNAVAILABLE; } else if (code == 504 && phrase.equals("Gateway Timeout")) { return GATEWAY_TIMEOUT; } else if (code == 505 && phrase.equals("HTTP Version Not Supported")) { return HTTP_VERSION_NOT_SUPPORTED; } else { return new HttpStatus(code, phrase); } } public static HttpStatus parseHttp(String string) { return Http.standardParser().parseStatusString(string); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpStatusParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Base10; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Utf8; final class HttpStatusParser extends Parser<HttpStatus> { final HttpParser http; final int code; final Output<String> phrase; final int step; HttpStatusParser(HttpParser http, int code, Output<String> phrase, int step) { this.http = http; this.code = code; this.phrase = phrase; this.step = step; } HttpStatusParser(HttpParser http) { this(http, 0, null, 1); } @Override public Parser<HttpStatus> feed(Input input) { return parse(input, this.http, this.code, this.phrase, this.step); } static Parser<HttpStatus> parse(Input input, HttpParser http, int code, Output<String> phrase, int step) { int c = 0; while (step <= 3) { if (input.isCont()) { c = input.head(); if (Base10.isDigit(c)) { input = input.step(); code = 10 * code + Base10.decodeDigit(c); step += 1; continue; } else { return error(Diagnostic.expected("status code", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("status code", input)); } break; } if (step == 4) { if (input.isCont() && input.head() == ' ') { input = input.step(); step = 5; } else if (!input.isEmpty()) { return error(Diagnostic.expected("space", input)); } } if (step == 5) { if (phrase == null) { phrase = Utf8.decodedString(); } while (input.isCont()) { c = input.head(); if (Http.isPhraseChar(c)) { input = input.step(); phrase.write(c); } else { break; } } if (!input.isEmpty()) { return done(http.status(code, phrase.bind())); } } if (input.isError()) { return error(input.trap()); } return new HttpStatusParser(http, code, phrase, step); } static Parser<HttpStatus> parse(Input input, HttpParser http) { return parse(input, http, 0, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpStatusWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Base10; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class HttpStatusWriter extends Writer<Object, Object> { final HttpWriter http; final int code; final String phrase; final Writer<?, ?> part; final int step; HttpStatusWriter(HttpWriter http, int code, String phrase, Writer<?, ?> part, int step) { this.http = http; this.code = code; this.phrase = phrase; this.part = part; this.step = step; } HttpStatusWriter(HttpWriter http, int code, String phrase) { this(http, code, phrase, null, 1); } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.http, this.code, this.phrase, this.part, this.step); } static Writer<Object, Object> write(Output<?> output, HttpWriter http, int code, String phrase, Writer<?, ?> part, int step) { if (step == 1 && output.isCont()) { if (code / 1000 != 0) { return error(new HttpException("invalid HTTP status code: " + code)); } output = output.write(Base10.encodeDigit(code / 100 % 10)); step = 2; } if (step == 2 && output.isCont()) { output = output.write(Base10.encodeDigit(code / 10 % 10)); step = 3; } if (step == 3 && output.isCont()) { output = output.write(Base10.encodeDigit(code % 10)); step = 4; } if (step == 4 && output.isCont()) { output = output.write(' '); step = 5; } if (step == 5) { if (part == null) { part = http.writePhrase(phrase, output); } else { part = part.pull(output); } if (part.isDone()) { return done(); } else if (part.isError()) { return part.asError(); } } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new HttpStatusWriter(http, code, phrase, part, step); } static Writer<Object, Object> write(Output<?> output, HttpWriter http, int code, String phrase) { return write(output, http, code, phrase, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpValue.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Debug; import swim.codec.Encoder; import swim.codec.Format; import swim.codec.Output; import swim.codec.OutputBuffer; import swim.collections.FingerTrieSeq; import swim.util.Murmur3; public final class HttpValue<T> extends HttpEntity<T> implements Debug { final T value; final MediaType mediaType; HttpValue(T value, MediaType mediaType) { this.value = value; this.mediaType = mediaType; } @Override public boolean isDefined() { return true; } @Override public T get() { return this.value; } @Override public long length() { return -1L; } @Override public MediaType mediaType() { return this.mediaType; } @Override public FingerTrieSeq<TransferCoding> transferCodings() { return FingerTrieSeq.empty(); } @Override public FingerTrieSeq<HttpHeader> headers() { return FingerTrieSeq.empty(); } @Override public <T2> Encoder<?, HttpMessage<T2>> httpEncoder(HttpMessage<T2> message, HttpWriter http) { throw new UnsupportedOperationException(); } @Override public <T2> Encoder<?, HttpMessage<T2>> encodeHttp(HttpMessage<T2> message, OutputBuffer<?> output, HttpWriter http) { throw new UnsupportedOperationException(); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof HttpValue<?>) { final HttpValue<?> that = (HttpValue<?>) other; return (this.value == null ? that.value == null : this.value.equals(that.value)) && (this.mediaType == null ? that.mediaType == null : this.mediaType.equals(that.mediaType)); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(HttpValue.class); } return Murmur3.mash(Murmur3.mix(Murmur3.mix(hashSeed, Murmur3.hash(this.value)), Murmur3.hash(this.mediaType))); } @Override public void debug(Output<?> output) { output = output.write("HttpValue").write('.').write("from").write('(').debug(this.value); if (this.mediaType != null) { output = output.write(", ").debug(this.mediaType); } output = output.write(')'); } @Override public String toString() { return Format.debug(this); } private static int hashSeed; public static <T> HttpValue<T> from(T value, MediaType mediaType) { return new HttpValue<T>(value, mediaType); } public static <T> HttpValue<T> from(T value) { return new HttpValue<T>(value, null); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpVersion.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Debug; import swim.codec.Format; import swim.codec.Output; import swim.codec.Writer; import swim.util.Murmur3; public final class HttpVersion extends HttpPart implements Debug { final int major; final int minor; HttpVersion(int major, int minor) { this.major = major; this.minor = minor; } public int major() { return this.major; } public int minor() { return this.minor; } @Override public Writer<?, ?> httpWriter(HttpWriter http) { return http.versionWriter(this.major, this.minor); } @Override public Writer<?, ?> writeHttp(Output<?> output, HttpWriter http) { return http.writeVersion(this.major, this.minor, output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof HttpVersion) { final HttpVersion that = (HttpVersion) other; return this.major == that.major && this.minor == that.minor; } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(HttpVersion.class); } return Murmur3.mash(Murmur3.mix(Murmur3.mix(hashSeed, this.major), this.minor)); } @Override public void debug(Output<?> output) { output = output.write("HttpVersion").write('.'); if (this.major == 1 && (this.minor == 1 || this.minor == 0)) { output = output.write("HTTP").write('_').debug(this.major).write('_').debug(this.minor); } else { output = output.write("from").write('(').debug(this.major).write(", ").debug(this.minor).write(')'); } } @Override public String toString() { return Format.debug(this); } private static int hashSeed; public static final HttpVersion HTTP_1_1 = new HttpVersion(1, 1); public static final HttpVersion HTTP_1_0 = new HttpVersion(1, 0); public static HttpVersion from(int major, int minor) { if (major == 1 && minor == 1) { return HTTP_1_1; } else if (major == 1 && minor == 0) { return HTTP_1_0; } else if (major >= 0 && minor >= 0) { return new HttpVersion(major, minor); } else { throw new IllegalArgumentException(major + ", " + minor); } } public static HttpVersion parseHttp(String string) { return Http.standardParser().parseVersionString(string); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpVersionParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Base10; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; final class HttpVersionParser extends Parser<HttpVersion> { final HttpParser http; final int major; final int minor; final int step; HttpVersionParser(HttpParser http, int major, int minor, int step) { this.http = http; this.major = major; this.minor = minor; this.step = step; } HttpVersionParser(HttpParser http) { this(http, 0, 0, 1); } @Override public Parser<HttpVersion> feed(Input input) { return parse(input, this.http, this.major, this.minor, this.step); } static Parser<HttpVersion> parse(Input input, HttpParser http, int major, int minor, int step) { int c = 0; if (step == 1) { if (input.isCont() && input.head() == 'H') { input = input.step(); step = 2; } else if (!input.isEmpty()) { return error(Diagnostic.expected('H', input)); } } if (step == 2) { if (input.isCont() && input.head() == 'T') { input = input.step(); step = 3; } else if (!input.isEmpty()) { return error(Diagnostic.expected('T', input)); } } if (step == 3) { if (input.isCont() && input.head() == 'T') { input = input.step(); step = 4; } else if (!input.isEmpty()) { return error(Diagnostic.expected('T', input)); } } if (step == 4) { if (input.isCont() && input.head() == 'P') { input = input.step(); step = 5; } else if (!input.isEmpty()) { return error(Diagnostic.expected('P', input)); } } if (step == 5) { if (input.isCont() && input.head() == '/') { input = input.step(); step = 6; } else if (!input.isEmpty()) { return error(Diagnostic.expected('/', input)); } } if (step == 6) { if (!input.isEmpty()) { c = input.head(); if (Base10.isDigit(c)) { input = input.step(); major = Base10.decodeDigit(c); step = 7; } else { return error(Diagnostic.expected("major version", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("major version", input)); } } if (step == 7) { if (input.isCont() && input.head() == '.') { input = input.step(); step = 8; } else if (!input.isEmpty()) { return error(Diagnostic.expected('.', input)); } } if (step == 8) { if (!input.isEmpty()) { c = input.head(); if (Base10.isDigit(c)) { input = input.step(); minor = Base10.decodeDigit(c); return done(http.version(major, minor)); } else { return error(Diagnostic.expected("minor version", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("minor version", input)); } } if (input.isError()) { return error(input.trap()); } return new HttpVersionParser(http, major, minor, step); } static Parser<HttpVersion> parse(Input input, HttpParser http) { return parse(input, http, 0, 0, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpVersionWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Base10; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class HttpVersionWriter extends Writer<Object, Object> { final int major; final int minor; final int step; HttpVersionWriter(int major, int minor, int step) { this.major = major; this.minor = minor; this.step = step; } HttpVersionWriter(int major, int minor) { this(major, minor, 1); } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.major, this.minor, this.step); } static Writer<Object, Object> write(Output<?> output, int major, int minor, int step) { if (step == 1 && output.isCont()) { output = output.write('H'); step = 2; } if (step == 2 && output.isCont()) { output = output.write('T'); step = 3; } if (step == 3 && output.isCont()) { output = output.write('T'); step = 4; } if (step == 4 && output.isCont()) { output = output.write('P'); step = 5; } if (step == 5 && output.isCont()) { output = output.write('/'); step = 6; } if (step == 6 && output.isCont()) { output = output.write(Base10.encodeDigit(major % 10)); step = 7; } if (step == 7 && output.isCont()) { output = output.write('.'); step = 8; } if (step == 8 && output.isCont()) { output = output.write(Base10.encodeDigit(minor % 10)); return done(); } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new HttpVersionWriter(major, minor, step); } static Writer<Object, Object> write(Output<?> output, int major, int minor) { return write(output, major, minor, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/HttpWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import java.util.Iterator; import java.util.Map; import swim.codec.Encoder; import swim.codec.Output; import swim.codec.OutputBuffer; import swim.codec.Writer; import swim.collections.HashTrieMap; public class HttpWriter { public <T> Writer<?, HttpRequest<T>> requestWriter(HttpRequest<T> request) { return new HttpRequestWriter<T>(this, request); } public <T> Writer<?, HttpRequest<T>> writeRequest(HttpRequest<T> request, Output<?> output) { return HttpRequestWriter.write(output, this, request); } public <T> Writer<?, HttpResponse<T>> responseWriter(HttpResponse<T> response) { return new HttpResponseWriter<T>(this, response); } public <T> Writer<?, HttpResponse<T>> writeResponse(HttpResponse<T> response, Output<?> output) { return HttpResponseWriter.write(output, this, response); } public Writer<?, ?> methodWriter(String name) { return new TokenWriter(name); } public Writer<?, ?> writeMethod(String name, Output<?> output) { return TokenWriter.write(output, name); } public Writer<?, ?> statusWriter(int code, String phrase) { return new HttpStatusWriter(this, code, phrase); } public Writer<?, ?> writeStatus(int code, String phrase, Output<?> output) { return HttpStatusWriter.write(output, this, code, phrase); } public Writer<?, ?> versionWriter(int major, int minor) { return new HttpVersionWriter(major, minor); } public Writer<?, ?> writeVersion(int major, int minor, Output<?> output) { return HttpVersionWriter.write(output, major, minor); } public Writer<?, ?> headerWriter(HttpHeader header) { return new HttpHeaderWriter(this, header); } public Writer<?, ?> writeHeader(HttpHeader header, Output<?> output) { return HttpHeaderWriter.write(output, this, header); } public Writer<?, ?> writeHeaderValue(HttpHeader header, Output<?> output) { return header.writeHttpValue(output, this); } public Writer<?, ?> chunkHeaderWriter(long size, Iterator<ChunkExtension> extensions) { return new HttpChunkHeaderWriter(this, size, extensions); } public Writer<?, ?> writeChunkHeader(long size, Iterator<ChunkExtension> extensions, Output<?> output) { return HttpChunkHeaderWriter.write(output, this, size, extensions); } public Writer<?, ?> chunkTrailerWriter(Iterator<HttpHeader> headers) { return new HttpChunkTrailerWriter(this, headers); } public Writer<?, ?> writeChunkTrailer(Iterator<HttpHeader> headers, Output<?> output) { return HttpChunkTrailerWriter.write(output, this, headers); } public Writer<?, ?> chunkExtensionWriter(String name, String value) { return new ParamWriter(this, name, value); } public Writer<?, ?> writeChunkExtension(String name, String value, Output<?> output) { return ParamWriter.write(output, this, name, value); } public Writer<?, ?> charsetWriter(String name, float weight) { if (weight == 1f) { return new TokenWriter(name); } else { return new HttpCharsetWriter(this, name, weight); } } public Writer<?, ?> writeCharset(String name, float weight, Output<?> output) { if (weight == 1f) { return TokenWriter.write(output, name); } else { return HttpCharsetWriter.write(output, this, name, weight); } } public Writer<?, ?> languageRangeWriter(String tag, String subtag, float weight) { return new LanguageRangeWriter(this, tag, subtag, weight); } public Writer<?, ?> writeLanguageRange(String tag, String subtag, float weight, Output<?> output) { return LanguageRangeWriter.write(output, this, tag, subtag, weight); } public Writer<?, ?> mediaRangeWriter(String type, String subtype, float weight, HashTrieMap<String, String> params) { return new MediaRangeWriter(this, type, subtype, weight, params); } public Writer<?, ?> writeMediaRange(String type, String subtype, float weight, HashTrieMap<String, String> params, Output<?> output) { return MediaRangeWriter.write(output, this, type, subtype, weight, params); } public Writer<?, ?> mediaTypeWriter(String type, String subtype, HashTrieMap<String, String> params) { return new MediaTypeWriter(this, type, subtype, params); } public Writer<?, ?> writeMediaType(String type, String subtype, HashTrieMap<String, String> params, Output<?> output) { return MediaTypeWriter.write(output, this, type, subtype, params); } public Writer<?, ?> productWriter(String name, String version, Iterator<String> comments) { return new ProductWriter(this, name, version, comments); } public Writer<?, ?> writeProduct(String name, String version, Iterator<String> comments, Output<?> output) { return ProductWriter.write(output, this, name, version, comments); } public Writer<?, ?> upgradeProtocolWriter(String name, String version) { return new UpgradeProtocolWriter(this, name, version); } public Writer<?, ?> writeUpgradeProtocol(String name, String version, Output<?> output) { return UpgradeProtocolWriter.write(output, this, name, version); } public Writer<?, ?> contentCodingWriter(String name, float weight) { if (weight == 1f) { return new TokenWriter(name); } else { return new ContentCodingWriter(this, name, weight); } } public Writer<?, ?> writeContentCoding(String name, float weight, Output<?> output) { if (weight == 1f) { return TokenWriter.write(output, name); } else { return ContentCodingWriter.write(output, this, name, weight); } } public Writer<?, ?> transferCodingWriter(String name, HashTrieMap<String, String> params) { if (params.isEmpty()) { return new TokenWriter(name); } else { return new TransferCodingWriter(this, name, params); } } public Writer<?, ?> writeTransferCoding(String name, HashTrieMap<String, String> params, Output<?> output) { if (params.isEmpty()) { return TokenWriter.write(output, name); } else { return TransferCodingWriter.write(output, this, name, params); } } public Writer<?, ?> webSocketParamWriter(String key, String value) { return new ParamWriter(this, key, value); } public Writer<?, ?> writeWebSocketParam(String key, String value, Output<?> output) { return ParamWriter.write(output, this, key, value); } public Writer<?, ?> webSocketExtensionWriter(String name, Iterator<WebSocketParam> params) { return new WebSocketExtensionWriter(this, name, params); } public Writer<?, ?> writeWebSocketExtension(String name, Iterator<WebSocketParam> params, Output<?> output) { return WebSocketExtensionWriter.write(output, this, name, params); } public Writer<?, ?> writeValue(String value, Output<?> output) { if (Http.isToken(value)) { return writeToken(value, output); } else { return writeQuoted(value, output); } } public Writer<?, ?> writeToken(String token, Output<?> output) { return TokenWriter.write(output, token); } public Writer<?, ?> writeQuoted(String quoted, Output<?> output) { return QuotedWriter.write(output, quoted); } public Writer<?, ?> writePhrase(String phrase, Output<?> output) { return PhraseWriter.write(output, phrase); } public Writer<?, ?> writeField(String field, Output<?> output) { return FieldWriter.write(output, field); } public Writer<?, ?> writeQValue(float weight, Output<?> output) { return QValueWriter.write(output, weight); } public Writer<?, ?> writeComments(Iterator<String> comments, Output<?> output) { return CommentsWriter.write(output, comments); } public Writer<?, ?> writeTokenList(Iterator<?> tokens, Output<?> output) { return TokenListWriter.write(output, tokens); } public Writer<?, ?> writeParam(String key, String value, Output<?> output) { return ParamWriter.write(output, this, key, value); } public Writer<?, ?> writeParamList(Iterator<? extends HttpPart> params, Output<?> output) { return ParamListWriter.write(output, this, params); } public Writer<?, ?> writeParamMap(Iterator<? extends Map.Entry<?, ?>> params, Output<?> output) { return ParamMapWriter.write(output, this, params); } public <T2> Encoder<?, HttpMessage<T2>> bodyEncoder(HttpMessage<T2> message, Encoder<?, ?> content, long length) { return new HttpBodyEncoder<T2>(message, content, length); } public <T2> Encoder<?, HttpMessage<T2>> encodeBody(HttpMessage<T2> message, Encoder<?, ?> content, long length, OutputBuffer<?> output) { return HttpBodyEncoder.encode(output, message, content, length); } public <T2> Encoder<?, HttpMessage<T2>> chunkedEncoder(HttpMessage<T2> message, Encoder<?, ?> content) { return new HttpChunkedEncoder<T2>(message, content); } public <T2> Encoder<?, HttpMessage<T2>> encodeChunked(HttpMessage<T2> message, Encoder<?, ?> content, OutputBuffer<?> output) { return HttpChunkedEncoder.encode(output, message, content); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/LanguageRange.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Debug; import swim.codec.Format; import swim.codec.Output; import swim.codec.Writer; import swim.util.Murmur3; public final class LanguageRange extends HttpPart implements Debug { final String tag; final String subtag; final float weight; LanguageRange(String tag, String subtag, float weight) { this.tag = tag; this.subtag = subtag; this.weight = weight; } LanguageRange(String tag, String subtag) { this(tag, subtag, 1f); } LanguageRange(String tag, float weight) { this(tag, null, weight); } LanguageRange(String tag) { this(tag, null, 1f); } public String tag() { return this.tag; } public String subtag() { return this.subtag; } public float weight() { return this.weight; } public LanguageRange weight(float weight) { return new LanguageRange(this.tag, this.subtag, weight); } @Override public Writer<?, ?> httpWriter(HttpWriter http) { return http.languageRangeWriter(this.tag, this.subtag, this.weight); } @Override public Writer<?, ?> writeHttp(Output<?> output, HttpWriter http) { return http.writeLanguageRange(this.tag, this.subtag, this.weight, output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof LanguageRange) { final LanguageRange that = (LanguageRange) other; return this.tag.equals(that.tag) && (this.subtag == null ? that.subtag == null : this.subtag.equals(that.subtag)) && this.weight == that.weight; } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(LanguageRange.class); } return Murmur3.mash(Murmur3.mix(Murmur3.mix(Murmur3.mix(hashSeed, this.tag.hashCode()), Murmur3.hash(this.subtag)), Murmur3.hash(this.weight))); } @Override public void debug(Output<?> output) { output = output.write("LanguageRange").write('.').write("from").write('(').debug(this.tag); if (this.subtag != null) { output = output.write(", ").debug(this.subtag); } if (this.weight != 1f) { output = output.write(", ").debug(this.weight); } output = output.write(')'); } @Override public String toString() { return Format.debug(this); } private static int hashSeed; private static LanguageRange star; public static LanguageRange star() { if (star == null) { star = new LanguageRange("*"); } return star; } public static LanguageRange from(String tag, String subtag, float weight) { if (weight == 1f) { return from(tag, subtag); } else { return new LanguageRange(tag, subtag, weight); } } public static LanguageRange from(String tag, String subtag) { if (subtag == null) { return from(tag); } else { return new LanguageRange(tag, subtag); } } public static LanguageRange from(String tag, float weight) { if (weight == 1f) { return from(tag); } else { return new LanguageRange(tag, weight); } } public static LanguageRange from(String tag) { if ("*".equals(tag)) { return star(); } else { return new LanguageRange(tag); } } public static LanguageRange parse(String string) { return Http.standardParser().parseLanguageRangeString(string); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/LanguageRangeParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Base10; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; final class LanguageRangeParser extends Parser<LanguageRange> { final HttpParser http; final StringBuilder tag; final StringBuilder subtag; final Parser<Float> weight; final int step; LanguageRangeParser(HttpParser http, StringBuilder tag, StringBuilder subtag, Parser<Float> weight, int step) { this.http = http; this.tag = tag; this.subtag = subtag; this.weight = weight; this.step = step; } LanguageRangeParser(HttpParser http) { this(http, null, null, null, 1); } @Override public Parser<LanguageRange> feed(Input input) { return parse(input, this.http, this.tag, this.subtag, this.weight, this.step); } static Parser<LanguageRange> parse(Input input, HttpParser http, StringBuilder tag, StringBuilder subtag, Parser<Float> weight, int step) { int c = 0; if (step == 1) { if (input.isCont()) { c = input.head(); if (Http.isAlpha(c)) { input = input.step(); if (tag == null) { tag = new StringBuilder(); } tag.appendCodePoint(c); step = 2; } else if (c == '*') { input = input.step(); tag = new StringBuilder("*"); step = 18; } else { return error(Diagnostic.expected("language tag", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("language tag", input)); } } while (step >= 2 && step <= 8) { if (input.isCont()) { c = input.head(); if (Http.isAlpha(c)) { input = input.step(); tag.appendCodePoint(c); step += 1; continue; } else if (c == '-') { input = input.step(); step = 9; break; } else { step = 18; break; } } else if (input.isDone()) { step = 18; break; } break; } if (step == 9) { if (input.isCont()) { c = input.head(); if (Http.isAlpha(c) || Base10.isDigit(c)) { input = input.step(); if (subtag == null) { subtag = new StringBuilder(); } subtag.appendCodePoint(c); step = 10; } else { return error(Diagnostic.expected("language subtag", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("language subtag", input)); } } while (step >= 10 && step <= 17) { if (input.isCont()) { c = input.head(); if (Http.isAlpha(c) || Base10.isDigit(c)) { input = input.step(); subtag.appendCodePoint(c); step += 1; continue; } else { step = 18; break; } } else if (input.isDone()) { step = 18; break; } break; } if (step == 18) { if (weight == null) { weight = http.parseQValue(input); } else { weight = weight.feed(input); } if (weight.isDone()) { final Float qvalue = weight.bind(); final float q = qvalue != null ? (float) qvalue : 1f; return done(http.languageRange(tag.toString(), subtag != null ? subtag.toString() : null, q)); } else if (weight.isError()) { return weight.asError(); } } if (input.isError()) { return error(input.trap()); } return new LanguageRangeParser(http, tag, subtag, weight, step); } static Parser<LanguageRange> parse(Input input, HttpParser http) { return parse(input, http, null, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/LanguageRangeWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class LanguageRangeWriter extends Writer<Object, Object> { final HttpWriter http; final String tag; final String subtag; final float weight; final Writer<?, ?> part; final int step; LanguageRangeWriter(HttpWriter http, String tag, String subtag, float weight, Writer<?, ?> part, int step) { this.http = http; this.tag = tag; this.subtag = subtag; this.weight = weight; this.part = part; this.step = step; } LanguageRangeWriter(HttpWriter http, String tag, String subtag, float weight) { this(http, tag, subtag, weight, null, 1); } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.http, this.tag, this.subtag, this.weight, this.part, this.step); } static Writer<Object, Object> write(Output<?> output, HttpWriter http, String tag, String subtag, float weight, Writer<?, ?> part, int step) { if (step == 1) { if (part == null) { part = http.writeField(tag, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; if (subtag != null) { step = 2; } else if (weight != 1f) { step = 4; } else { return done(); } } else if (part.isError()) { return part.asError(); } } if (step == 2 && output.isCont()) { output = output.write('-'); step = 3; } if (step == 3) { if (part == null) { part = http.writeField(subtag, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; if (weight != 1f) { step = 4; } else { return done(); } } else if (part.isError()) { return part.asError(); } } if (step == 4) { if (part == null) { part = http.writeQValue(weight, output); } else { part = part.pull(output); } if (part.isDone()) { return done(); } else if (part.isError()) { return part.asError(); } } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new LanguageRangeWriter(http, tag, subtag, weight, part, step); } static Writer<Object, Object> write(Output<?> output, HttpWriter http, String tag, String subtag, float weight) { return write(output, http, tag, subtag, weight, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/MediaRange.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Debug; import swim.codec.Format; import swim.codec.Output; import swim.codec.Writer; import swim.collections.HashTrieMap; import swim.util.Murmur3; public final class MediaRange extends HttpPart implements Debug { final String type; final String subtype; final float weight; final HashTrieMap<String, String> params; MediaRange(String type, String subtype, float weight, HashTrieMap<String, String> params) { this.type = type; this.subtype = subtype; this.weight = weight; this.params = params; } MediaRange(String type, String subtype, float weight) { this(type, subtype, weight, HashTrieMap.<String, String>empty()); } MediaRange(String type, String subtype, HashTrieMap<String, String> params) { this(type, subtype, 1f, params); } MediaRange(String type, String subtype) { this(type, subtype, 1f, HashTrieMap.<String, String>empty()); } public boolean isApplication() { return "application".equalsIgnoreCase(this.type); } public boolean isAudio() { return "audio".equalsIgnoreCase(this.type); } public boolean isImage() { return "image".equalsIgnoreCase(this.type); } public boolean isMultipart() { return "multipart".equalsIgnoreCase(this.type); } public boolean isText() { return "text".equalsIgnoreCase(this.type); } public boolean isVideo() { return "video".equalsIgnoreCase(this.type); } public String type() { return this.type; } public String subtype() { return this.subtype; } public float weight() { return this.weight; } public MediaRange weight(float weight) { return new MediaRange(this.type, this.subtype, weight, this.params); } public HashTrieMap<String, String> params() { return this.params; } public String getParam(String key) { return this.params.get(key); } public MediaRange param(String key, String value) { return new MediaRange(this.type, this.subtype, this.weight, this.params.updated(key, value)); } @Override public Writer<?, ?> httpWriter(HttpWriter http) { return http.mediaRangeWriter(this.type, this.subtype, this.weight, this.params); } @Override public Writer<?, ?> writeHttp(Output<?> output, HttpWriter http) { return http.writeMediaRange(this.type, this.subtype, this.weight, this.params, output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof MediaRange) { final MediaRange that = (MediaRange) other; return this.type.equals(that.type) && this.subtype.equals(that.subtype) && this.weight == that.weight && this.params.equals(that.params); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(MediaRange.class); } return Murmur3.mash(Murmur3.mix(Murmur3.mix(Murmur3.mix(Murmur3.mix( hashSeed, this.type.hashCode()), this.subtype.hashCode()), Murmur3.hash(this.weight)), this.params.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("MediaRange").write('.').write("from").write('(') .debug(this.type).write(", ").debug(this.subtype); if (this.weight != 1f) { output = output.write(", ").debug(this.weight); } output = output.write(')'); for (HashTrieMap.Entry<String, String> param : this.params) { output = output.write('.').write("param").write('(') .debug(param.getKey()).write(", ").debug(param.getValue()).write(')'); } } @Override public String toString() { return Format.debug(this); } private static int hashSeed; public static MediaRange from(String type, String subtype, float weight, HashTrieMap<String, String> params) { return new MediaRange(type, subtype, weight, params); } public static MediaRange from(String type, String subtype, float weight) { return new MediaRange(type, subtype, weight); } public static MediaRange from(String type, String subtype, HashTrieMap<String, String> params) { return new MediaRange(type, subtype, params); } public static MediaRange from(String type, String subtype) { return new MediaRange(type, subtype); } public static MediaRange parse(String string) { return Http.standardParser().parseMediaRangeString(string); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/MediaRangeParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.collections.HashTrieMap; final class MediaRangeParser extends Parser<MediaRange> { final HttpParser http; final StringBuilder type; final StringBuilder subtype; final Parser<Float> weight; final Parser<HashTrieMap<String, String>> params; final int step; MediaRangeParser(HttpParser http, StringBuilder type, StringBuilder subtype, Parser<Float> weight, Parser<HashTrieMap<String, String>> params, int step) { this.http = http; this.type = type; this.subtype = subtype; this.weight = weight; this.params = params; this.step = step; } MediaRangeParser(HttpParser http) { this(http, null, null, null, null, 1); } @Override public Parser<MediaRange> feed(Input input) { return parse(input, this.http, this.type, this.subtype, this.weight, this.params, this.step); } static Parser<MediaRange> parse(Input input, HttpParser http, StringBuilder type, StringBuilder subtype, Parser<Float> weight, Parser<HashTrieMap<String, String>> params, int step) { int c = 0; if (step == 1) { if (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); if (type == null) { type = new StringBuilder(); } type.appendCodePoint(c); step = 2; } else { return error(Diagnostic.expected("media type", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("media type", input)); } } if (step == 2) { while (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); type.appendCodePoint(c); } else { break; } } if (input.isCont() && c == '/') { input = input.step(); step = 3; } else if (!input.isEmpty()) { return error(Diagnostic.expected('/', input)); } } if (step == 3) { if (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); if (subtype == null) { subtype = new StringBuilder(); } subtype.appendCodePoint(c); step = 4; } else { return error(Diagnostic.expected("media subtype", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("media subtype", input)); } } if (step == 4) { while (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); subtype.appendCodePoint(c); } else { break; } } if (!input.isEmpty()) { step = 5; } } if (step == 5) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont() && c == ';') { input = input.step(); step = 6; } else if (!input.isEmpty()) { return done(http.mediaRange(type.toString(), subtype.toString(), 1f, HashTrieMap.<String, String>empty())); } } if (step == 6) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (c == 'q') { input = input.step(); step = 7; } else { params = http.parseParamMapRest(input); step = 9; } } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } if (step == 7) { if (input.isCont()) { c = input.head(); if (c == '=') { weight = http.parseQValueRest(input); step = 8; } else { params = http.parseParamMapRest(new StringBuilder().append('q'), input); step = 9; } } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } if (step == 8) { weight = weight.feed(input); if (weight.isDone()) { step = 9; } else if (weight.isError()) { return weight.asError(); } } if (step == 9) { if (params == null) { params = http.parseParamMap(input); } else { params = params.feed(input); } if (params.isDone()) { final Float qvalue = weight != null ? weight.bind() : null; final float q = qvalue != null ? (float) qvalue : 1f; return done(http.mediaRange(type.toString(), subtype.toString(), q, params.bind())); } else if (params.isError()) { return params.asError(); } } if (input.isError()) { return error(input.trap()); } return new MediaRangeParser(http, type, subtype, weight, params, step); } static Parser<MediaRange> parse(Input input, HttpParser http) { return parse(input, http, null, null, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/MediaRangeWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; import swim.collections.HashTrieMap; final class MediaRangeWriter extends Writer<Object, Object> { final HttpWriter http; final String type; final String subtype; final float weight; final HashTrieMap<String, String> params; final Writer<?, ?> part; final int step; MediaRangeWriter(HttpWriter http, String type, String subtype, float weight, HashTrieMap<String, String> params, Writer<?, ?> part, int step) { this.http = http; this.type = type; this.subtype = subtype; this.weight = weight; this.params = params; this.part = part; this.step = step; } MediaRangeWriter(HttpWriter http, String type, String subtype, float weight, HashTrieMap<String, String> params) { this(http, type, subtype, weight, params, null, 1); } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.http, this.type, this.subtype, this.weight, this.params, this.part, this.step); } static Writer<Object, Object> write(Output<?> output, HttpWriter http, String type, String subtype, float weight, HashTrieMap<String, String> params, Writer<?, ?> part, int step) { if (step == 1) { if (part == null) { part = http.writeToken(type, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 2; } else if (part.isError()) { return part.asError(); } } if (step == 2 && output.isCont()) { output = output.write('/'); step = 3; } if (step == 3) { if (part == null) { part = http.writeToken(subtype, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; if (weight != 1f) { step = 4; } else if (!params.isEmpty()) { step = 5; } else { return done(); } } else if (part.isError()) { return part.asError(); } } if (step == 4) { if (part == null) { part = http.writeQValue(weight, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; if (!params.isEmpty()) { step = 5; } else { return done(); } } else if (part.isError()) { return part.asError(); } } if (step == 5) { if (part == null) { part = http.writeParamMap(params.iterator(), output); } else { part = part.pull(output); } if (part.isDone()) { return done(); } else if (part.isError()) { return part.asError(); } } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new MediaRangeWriter(http, type, subtype, weight, params, part, step); } static Writer<Object, Object> write(Output<?> output, HttpWriter http, String type, String subtype, float weight, HashTrieMap<String, String> params) { return write(output, http, type, subtype, weight, params, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/MediaType.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Debug; import swim.codec.Format; import swim.codec.Output; import swim.codec.Writer; import swim.collections.HashTrieMap; import swim.util.Murmur3; public final class MediaType extends HttpPart implements Debug { final String type; final String subtype; final HashTrieMap<String, String> params; MediaType(String type, String subtype, HashTrieMap<String, String> params) { this.type = type; this.subtype = subtype; this.params = params; } MediaType(String type, String subtype) { this(type, subtype, HashTrieMap.<String, String>empty()); } public boolean isApplication() { return "application".equalsIgnoreCase(type); } public boolean isAudio() { return "audio".equalsIgnoreCase(type); } public boolean isImage() { return "image".equalsIgnoreCase(type); } public boolean isMultipart() { return "multipart".equalsIgnoreCase(type); } public boolean isText() { return "text".equalsIgnoreCase(type); } public boolean isVideo() { return "video".equalsIgnoreCase(type); } public String type() { return this.type; } public String subtype() { return this.subtype; } public HashTrieMap<String, String> params() { return this.params; } public String getParam(String key) { return this.params.get(key); } public MediaType param(String key, String value) { return MediaType.from(this.type, this.subtype, this.params.updated(key, value)); } @Override public Writer<?, ?> httpWriter(HttpWriter http) { return http.mediaTypeWriter(this.type, this.subtype, this.params); } @Override public Writer<?, ?> writeHttp(Output<?> output, HttpWriter http) { return http.writeMediaType(this.type, this.subtype, this.params, output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof MediaType) { final MediaType that = (MediaType) other; return this.type.equals(that.type) && this.subtype.equals(that.subtype) && this.params.equals(that.params); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(MediaType.class); } return Murmur3.mash(Murmur3.mix(Murmur3.mix(Murmur3.mix(hashSeed, this.type.hashCode()), this.subtype.hashCode()), this.params.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("MediaType").write('.').write("from").write('(') .debug(this.type).write(", ").write(this.subtype).write(')'); for (HashTrieMap.Entry<String, String> param : this.params) { output = output.write('.').write("param").write('(') .debug(param.getKey()).write(", ").debug(param.getValue()).write(')'); } } @Override public String toString() { return Format.debug(this); } private static int hashSeed; private static MediaType applicationJavascript; private static MediaType applicationJson; private static MediaType applicationOctetStream; private static MediaType applicationXml; private static MediaType applicationXRecon; private static MediaType imageJpeg; private static MediaType imagePng; private static MediaType imageSvgXml; private static MediaType textCss; private static MediaType textHtml; private static MediaType textPlain; public static MediaType applicationJavascript() { if (applicationJavascript == null) { applicationJavascript = new MediaType("application", "javascript"); } return applicationJavascript; } public static MediaType applicationJson() { if (applicationJson == null) { applicationJson = new MediaType("application", "json"); } return applicationJson; } public static MediaType applicationOctetStream() { if (applicationOctetStream == null) { applicationOctetStream = new MediaType("application", "octet-stream"); } return applicationOctetStream; } public static MediaType applicationXml() { if (applicationXml == null) { applicationXml = new MediaType("application", "xml"); } return applicationXml; } public static MediaType applicationXRecon() { if (applicationXRecon == null) { applicationXRecon = new MediaType("application", "x-recon"); } return applicationXRecon; } public static MediaType imageJpeg() { if (imageJpeg == null) { imageJpeg = new MediaType("image", "jpeg"); } return imageJpeg; } public static MediaType imagePng() { if (imagePng == null) { imagePng = new MediaType("image", "png"); } return imagePng; } public static MediaType imageSvgXml() { if (imageSvgXml == null) { imageSvgXml = new MediaType("image", "svg+xml"); } return imageSvgXml; } public static MediaType textCss() { if (textCss == null) { textCss = new MediaType("text", "css"); } return textCss; } public static MediaType textHtml() { if (textHtml == null) { textHtml = new MediaType("text", "html"); } return textHtml; } public static MediaType textPlain() { if (textPlain == null) { textPlain = new MediaType("text", "plain"); } return textPlain; } public static MediaType from(String type, String subtype, HashTrieMap<String, String> params) { if (params.isEmpty()) { if ("application".equals(type)) { if ("javascript".equals(subtype)) { return applicationJavascript(); } else if ("json".equals(subtype)) { return applicationJson(); } else if ("octet-stream".equals(subtype)) { return applicationOctetStream(); } else if ("xml".equals(subtype)) { return applicationXml(); } else if ("x-recon".equals(subtype)) { return applicationXRecon(); } } else if ("image".equals(type)) { if ("jpeg".equals(subtype)) { return imageJpeg(); } else if ("png".equals(subtype)) { return imagePng(); } else if ("svg+xml".equals(subtype)) { return imageSvgXml(); } } else if ("text".equals(type)) { if ("css".equals(subtype)) { return textCss(); } else if ("html".equals(subtype)) { return textHtml(); } else if ("plain".equals(subtype)) { return textPlain(); } } } return new MediaType(type, subtype, params); } public static MediaType from(String type, String subtype) { return from(type, subtype, HashTrieMap.<String, String>empty()); } public static MediaType parse(String string) { return Http.standardParser().parseMediaTypeString(string); } public static MediaType forPath(String path) { if (path.endsWith(".js")) { return applicationJavascript(); } else if (path.endsWith(".json")) { return applicationJson(); } else if (path.endsWith(".xml")) { return applicationXml(); } else if (path.endsWith(".recon")) { return applicationXRecon(); } else if (path.endsWith(".jpeg") || path.endsWith(".jpg")) { return imageJpeg(); } else if (path.endsWith(".png")) { return imagePng(); } else if (path.endsWith(".svg")) { return imageSvgXml(); } else if (path.endsWith(".css")) { return textCss(); } else if (path.endsWith(".html")) { return textHtml(); } else if (path.endsWith(".txt")) { return textPlain(); } else { return null; } } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/MediaTypeParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.collections.HashTrieMap; final class MediaTypeParser extends Parser<MediaType> { final HttpParser http; final StringBuilder type; final StringBuilder subtype; final Parser<HashTrieMap<String, String>> params; final int step; MediaTypeParser(HttpParser http, StringBuilder type, StringBuilder subtype, Parser<HashTrieMap<String, String>> params, int step) { this.http = http; this.type = type; this.subtype = subtype; this.params = params; this.step = step; } MediaTypeParser(HttpParser http) { this(http, null, null, null, 1); } @Override public Parser<MediaType> feed(Input input) { return parse(input, this.http, this.type, this.subtype, this.params, this.step); } static Parser<MediaType> parse(Input input, HttpParser http, StringBuilder type, StringBuilder subtype, Parser<HashTrieMap<String, String>> params, int step) { int c = 0; if (step == 1) { if (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); if (type == null) { type = new StringBuilder(); } type.appendCodePoint(c); step = 2; } else { return error(Diagnostic.expected("media type", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("media type", input)); } } if (step == 2) { while (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); type.appendCodePoint(c); } else { break; } } if (input.isCont() && c == '/') { input = input.step(); step = 3; } else if (!input.isEmpty()) { return error(Diagnostic.expected('/', input)); } } if (step == 3) { if (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); if (subtype == null) { subtype = new StringBuilder(); } subtype.appendCodePoint(c); step = 4; } else { return error(Diagnostic.expected("media subtype", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("media subtype", input)); } } if (step == 4) { while (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); subtype.appendCodePoint(c); } else { break; } } if (!input.isEmpty()) { step = 5; } } if (step == 5) { if (params == null) { params = http.parseParamMap(input); } else { params = params.feed(input); } if (params.isDone()) { return done(http.mediaType(type.toString(), subtype.toString(), params.bind())); } else if (params.isError()) { return params.asError(); } } if (input.isError()) { return error(input.trap()); } return new MediaTypeParser(http, type, subtype, params, step); } static Parser<MediaType> parse(Input input, HttpParser http) { return parse(input, http, null, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/MediaTypeWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; import swim.collections.HashTrieMap; final class MediaTypeWriter extends Writer<Object, Object> { final HttpWriter http; final String type; final String subtype; final HashTrieMap<String, String> params; final Writer<?, ?> part; final int step; MediaTypeWriter(HttpWriter http, String type, String subtype, HashTrieMap<String, String> params, Writer<?, ?> part, int step) { this.http = http; this.type = type; this.subtype = subtype; this.params = params; this.part = part; this.step = step; } MediaTypeWriter(HttpWriter http, String type, String subtype, HashTrieMap<String, String> params) { this(http, type, subtype, params, null, 1); } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.http, this.type, this.subtype, this.params, this.part, this.step); } static Writer<Object, Object> write(Output<?> output, HttpWriter http, String type, String subtype, HashTrieMap<String, String> params, Writer<?, ?> part, int step) { if (step == 1) { if (part == null) { part = http.writeToken(type, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 2; } else if (part.isError()) { return part.asError(); } } if (step == 2 && output.isCont()) { output = output.write('/'); step = 3; } if (step == 3) { if (part == null) { part = http.writeToken(subtype, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; if (!params.isEmpty()) { step = 4; } else { return done(); } } else if (part.isError()) { return part.asError(); } } if (step == 4) { if (part == null) { part = http.writeParamMap(params.iterator(), output); } else { part = part.pull(output); } if (part.isDone()) { return done(); } else if (part.isError()) { return part.asError(); } } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new MediaTypeWriter(http, type, subtype, params, part, step); } static Writer<Object, Object> write(Output<?> output, HttpWriter http, String type, String subtype, HashTrieMap<String, String> params) { return write(output, http, type, subtype, params, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/ParamListWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import java.util.Iterator; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class ParamListWriter extends Writer<Object, Object> { final HttpWriter http; final Iterator<? extends HttpPart> params; final Writer<?, ?> param; final int step; ParamListWriter(HttpWriter http, Iterator<? extends HttpPart> params, Writer<?, ?> param, int step) { this.http = http; this.params = params; this.param = param; this.step = step; } ParamListWriter(HttpWriter http, Iterator<? extends HttpPart> params) { this(http, params, null, 1); } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.http, this.params, this.param, this.step); } static Writer<Object, Object> write(Output<?> output, HttpWriter http, Iterator<? extends HttpPart> params, Writer<?, ?> param, int step) { do { if (step == 1) { if (param == null) { if (!params.hasNext()) { return done(); } else { param = params.next().writeHttp(output, http); } } else { param = param.pull(output); } if (param.isDone()) { param = null; if (!params.hasNext()) { return done(); } else { step = 2; } } else if (param.isError()) { return param.asError(); } } if (step == 2 && output.isCont()) { output = output.write(','); step = 3; } if (step == 3 && output.isCont()) { output = output.write(' '); step = 1; continue; } break; } while (true); if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new ParamListWriter(http, params, param, step); } static Writer<Object, Object> write(Output<?> output, HttpWriter http, Iterator<? extends HttpPart> params) { return write(output, http, params, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/ParamMapParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.collections.HashTrieMap; final class ParamMapParser extends Parser<HashTrieMap<String, String>> { final StringBuilder key; final StringBuilder value; final HashTrieMap<String, String> params; final int step; ParamMapParser(StringBuilder key, StringBuilder value, HashTrieMap<String, String> params, int step) { this.key = key; this.value = value; this.params = params; this.step = step; } @Override public Parser<HashTrieMap<String, String>> feed(Input input) { return parse(input, this.key, this.value, this.params, this.step); } static Parser<HashTrieMap<String, String>> parse(Input input, StringBuilder key, StringBuilder value, HashTrieMap<String, String> params, int step) { int c = 0; do { if (step == 1) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont() && c == ';') { input = input.step(); step = 2; } else if (!input.isEmpty()) { if (params == null) { params = HashTrieMap.empty(); } return done(params); } } if (step == 2) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (Http.isTokenChar(c)) { key = new StringBuilder(); input = input.step(); key.appendCodePoint(c); step = 3; } else { return error(Diagnostic.expected("param name", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("param name", input)); } } if (step == 3) { while (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); key.appendCodePoint(c); } else { break; } } if (input.isCont()) { step = 4; } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } if (step == 4) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont() && c == '=') { input = input.step(); step = 5; } else if (!input.isEmpty()) { return error(Diagnostic.expected('=', input)); } } if (step == 5) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (value == null) { value = new StringBuilder(); } if (c == '"') { input = input.step(); step = 8; } else { step = 6; } } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } if (step == 6) { if (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); value.appendCodePoint(c); step = 7; } else { return error(Diagnostic.expected("param value", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("param value", input)); } } if (step == 7) { while (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); value.appendCodePoint(c); } else { break; } } if (!input.isEmpty()) { if (params == null) { params = HashTrieMap.empty(); } params = params.updated(key.toString(), value.toString()); key = null; value = null; step = 1; continue; } } if (step == 8) { while (input.isCont()) { c = input.head(); if (Http.isQuotedChar(c)) { input = input.step(); value.appendCodePoint(c); } else { break; } } if (input.isCont()) { if (c == '"') { input = input.step(); if (params == null) { params = HashTrieMap.empty(); } params = params.updated(key.toString(), value.toString()); key = null; value = null; step = 1; continue; } else if (c == '\\') { input = input.step(); step = 9; } else { return error(Diagnostic.unexpected(input)); } } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } if (step == 9) { if (input.isCont()) { c = input.head(); if (Http.isEscapeChar(c)) { input = input.step(); value.appendCodePoint(c); step = 8; continue; } else { return error(Diagnostic.expected("escape character", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("escape character", input)); } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new ParamMapParser(key, value, params, step); } static Parser<HashTrieMap<String, String>> parse(Input input) { return parse(input, null, null, null, 1); } static Parser<HashTrieMap<String, String>> parseRest(Input input) { return parse(input, null, null, null, 2); } static Parser<HashTrieMap<String, String>> parseRest(Input input, StringBuilder key) { return parse(input, key, null, null, 3); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/ParamMapWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import java.util.Iterator; import java.util.Map; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class ParamMapWriter extends Writer<Object, Object> { final HttpWriter http; final Iterator<? extends Map.Entry<?, ?>> params; final Writer<?, ?> part; final int step; ParamMapWriter(HttpWriter http, Iterator<? extends Map.Entry<?, ?>> params, Writer<?, ?> part, int step) { this.http = http; this.params = params; this.part = part; this.step = step; } ParamMapWriter(HttpWriter http, Iterator<? extends Map.Entry<?, ?>> params) { this(http, params, null, 1); } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.http, this.params, this.part, this.step); } static Writer<Object, Object> write(Output<?> output, HttpWriter http, Iterator<? extends Map.Entry<?, ?>> params, Writer<?, ?> part, int step) { do { if (step == 1) { if (!params.hasNext()) { return done(); } else if (output.isCont()) { output = output.write(';'); step = 2; } } if (step == 2 && output.isCont()) { output = output.write(' '); step = 3; } if (step == 3) { if (part == null) { final Map.Entry<?, ?> param = params.next(); part = http.writeParam(param.getKey().toString(), param.getValue().toString(), output); } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 1; continue; } else if (part.isError()) { return part.asError(); } } break; } while (true); if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new ParamMapWriter(http, params, part, step); } public static Writer<Object, Object> write(Output<?> output, HttpWriter http, Iterator<? extends Map.Entry<?, ?>> params) { return write(output, http, params, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/ParamWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class ParamWriter extends Writer<Object, Object> { final HttpWriter http; final String key; final String value; final Writer<?, ?> part; final int step; ParamWriter(HttpWriter http, String key, String value, Writer<?, ?> part, int step) { this.http = http; this.key = key; this.value = value; this.part = part; this.step = step; } ParamWriter(HttpWriter http, String key, String value) { this(http, key, value, null, 1); } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.http, this.key, this.value, this.part, this.step); } static Writer<Object, Object> write(Output<?> output, HttpWriter http, String key, String value, Writer<?, ?> part, int step) { if (step == 1) { if (part == null) { part = http.writeToken(key, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; if (value.isEmpty()) { return done(); } else { step = 2; } } else if (part.isError()) { return part.asError(); } } if (step == 2 && output.isCont()) { output = output.write('='); step = 3; } if (step == 3) { if (part == null) { part = http.writeValue(value, output); } else { part = part.pull(output); } if (part.isDone()) { return done(); } else if (part.isError()) { return part.asError(); } } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new ParamWriter(http, key, value, part, step); } static Writer<Object, Object> write(Output<?> output, HttpWriter http, String key, String value) { return write(output, http, key, value, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/PhraseWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class PhraseWriter extends Writer<Object, Object> { final String phrase; final int index; PhraseWriter(String phrase, int index) { this.phrase = phrase; this.index = index; } PhraseWriter(String phrase) { this(phrase, 0); } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.phrase, this.index); } static Writer<Object, Object> write(Output<?> output, String phrase, int index) { final int length = phrase.length(); while (index < length && output.isCont()) { final int c = phrase.codePointAt(index); if (Http.isPhraseChar(c)) { output = output.write(c); index = phrase.offsetByCodePoints(index, 1); } else { return error(new HttpException("invalid phrase: " + phrase)); } } if (index >= length) { return done(); } else if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new PhraseWriter(phrase, index); } static Writer<Object, Object> write(Output<?> output, String phrase) { return write(output, phrase, 0); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/Product.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Debug; import swim.codec.Format; import swim.codec.Output; import swim.codec.Writer; import swim.collections.FingerTrieSeq; import swim.util.Murmur3; public final class Product extends HttpPart implements Debug { final String name; final String version; final FingerTrieSeq<String> comments; Product(String name, String version, FingerTrieSeq<String> comments) { this.name = name; this.version = version; this.comments = comments; } Product(String name, String version) { this(name, version, FingerTrieSeq.<String>empty()); } Product(String name) { this(name, null, FingerTrieSeq.<String>empty()); } public String name() { return this.name; } public String version() { return this.version; } public FingerTrieSeq<String> comments() { return this.comments; } public Product comments(FingerTrieSeq<String> comments) { return new Product(this.name, this.version, comments); } public Product comment(String comment) { return new Product(this.name, this.version, this.comments.appended(comment)); } @Override public Writer<?, ?> httpWriter(HttpWriter http) { return http.productWriter(this.name, this.version, this.comments.iterator()); } @Override public Writer<?, ?> writeHttp(Output<?> output, HttpWriter http) { return http.writeProduct(this.name, this.version, this.comments.iterator(), output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof Product) { final Product that = (Product) other; return this.name.equals(that.name) && (this.version == null ? that.version == null : this.version.equals(that.version)) && this.comments.equals(that.comments); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(Product.class); } return Murmur3.mash(Murmur3.mix(Murmur3.mix(Murmur3.mix(hashSeed, this.name.hashCode()), Murmur3.hash(this.version)), this.comments.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("Product").write('.').write("from").write('(').debug(this.name); if (this.version != null) { output = output.write(", ").debug(this.version); } output = output.write(')'); for (String comment : this.comments) { output = output.write('.').write("comment").write('(').debug(comment).write(')'); } } @Override public String toString() { return Format.debug(this); } private static int hashSeed; public static Product from(String name, String version, FingerTrieSeq<String> comments) { return new Product(name, version, comments); } public static Product from(String name, String version, String... comments) { return new Product(name, version, FingerTrieSeq.of(comments)); } public static Product from(String name, String version) { return new Product(name, version); } public static Product from(String name) { return new Product(name); } public static Product parse(String string) { return Http.standardParser().parseProductString(string); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/ProductParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.collections.FingerTrieSeq; import swim.util.Builder; final class ProductParser extends Parser<Product> { final HttpParser http; final StringBuilder name; final StringBuilder version; final Builder<String, FingerTrieSeq<String>> comments; final Parser<String> comment; final int step; ProductParser(HttpParser http, StringBuilder name, StringBuilder version, Builder<String, FingerTrieSeq<String>> comments, Parser<String> comment, int step) { this.http = http; this.name = name; this.version = version; this.comments = comments; this.comment = comment; this.step = step; } ProductParser(HttpParser http) { this(http, null, null, null, null, 1); } @Override public Parser<Product> feed(Input input) { return parse(input, this.http, this.name, this.version, this.comments, this.comment, this.step); } static Parser<Product> parse(Input input, HttpParser http, StringBuilder name, StringBuilder version, Builder<String, FingerTrieSeq<String>> comments, Parser<String> comment, int step) { int c = 0; if (step == 1) { if (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); if (name == null) { name = new StringBuilder(); } name.appendCodePoint(c); step = 2; } else { return error(Diagnostic.expected("product name", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("product name", input)); } } if (step == 2) { while (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); name.appendCodePoint(c); } else { break; } } if (input.isCont() && c == '/') { input = input.step(); step = 3; } else if (!input.isEmpty()) { step = 5; } } if (step == 3) { if (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); if (version == null) { version = new StringBuilder(); } version.appendCodePoint(c); step = 4; } else { return error(Diagnostic.expected("product version", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("product version", input)); } } if (step == 4) { while (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); version.appendCodePoint(c); } else { break; } } if (!input.isEmpty()) { step = 5; } } do { if (step == 5) { if (input.isCont() && Http.isSpace(input.head())) { input = input.step(); step = 6; } else if (!input.isEmpty()) { return done(http.product(name.toString(), version != null ? version.toString() : null, comments != null ? comments.bind() : FingerTrieSeq.<String>empty())); } } if (step == 6) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (c == '(') { step = 7; } else { step = 5; continue; } } else if (input.isDone()) { step = 5; continue; } } if (step == 7) { if (comment == null) { comment = http.parseComment(input); } else { comment = comment.feed(input); } if (comment.isDone()) { if (comments == null) { comments = FingerTrieSeq.builder(); } comments.add(comment.bind()); comment = null; step = 5; continue; } else if (comment.isError()) { return comment.asError(); } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new ProductParser(http, name, version, comments, comment, step); } static Parser<Product> parse(Input input, HttpParser http) { return parse(input, http, null, null, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/ProductWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import java.util.Iterator; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class ProductWriter extends Writer<Object, Object> { final HttpWriter http; final String name; final String version; final Iterator<String> comments; final Writer<?, ?> part; final int step; ProductWriter(HttpWriter http, String name, String version, Iterator<String> comments, Writer<?, ?> part, int step) { this.http = http; this.name = name; this.version = version; this.comments = comments; this.part = part; this.step = step; } ProductWriter(HttpWriter http, String name, String version, Iterator<String> comments) { this(http, name, version, comments, null, 1); } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.http, this.name, this.version, this.comments, this.part, this.step); } static Writer<Object, Object> write(Output<?> output, HttpWriter http, String name, String version, Iterator<String> comments, Writer<?, ?> part, int step) { if (step == 1) { if (part == null) { part = http.writeToken(name, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; if (version != null) { step = 2; } else if (comments.hasNext()) { step = 4; } else { return done(); } } else if (part.isError()) { return part.asError(); } } if (step == 2 && output.isCont()) { output = output.write('/'); step = 3; } if (step == 3) { if (part == null) { part = http.writeToken(version, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; if (comments.hasNext()) { step = 4; } else { return done(); } } else if (part.isError()) { return part.asError(); } } if (step == 4) { if (part == null) { part = http.writeComments(comments, output); } else { part = part.pull(output); } if (part.isDone()) { return done(); } else if (part.isError()) { return part.asError(); } } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new ProductWriter(http, name, version, comments, part, step); } static Writer<Object, Object> write(Output<?> output, HttpWriter http, String name, String version, Iterator<String> comments) { return write(output, http, name, version, comments, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/QValueParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Base10; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; final class QValueParser extends Parser<Float> { final int significand; final int exponent; final int step; QValueParser(int significand, int exponent, int step) { this.significand = significand; this.exponent = exponent; this.step = step; } @Override public Parser<Float> feed(Input input) { return parse(input, this.significand, this.exponent, this.step); } static Parser<Float> parse(Input input, int significand, int exponent, int step) { int c = 0; if (step == 1) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont() && c == ';') { input = input.step(); step = 2; } else if (!input.isEmpty()) { return done(); } } if (step == 2) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (c == 'q') { input = input.step(); step = 3; } else { return error(Diagnostic.expected("qvalue", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("qvalue", input)); } } if (step == 3) { if (input.isCont()) { c = input.head(); if (c == '=') { input = input.step(); step = 4; } else { return error(Diagnostic.expected('=', input)); } } else if (input.isDone()) { return error(Diagnostic.expected('=', input)); } } if (step == 4) { if (input.isCont()) { c = input.head(); if (c == '0') { input = input.step(); significand = 0; exponent = 0; step = 5; } else if (c == '1') { input = input.step(); significand = 1; exponent = 0; step = 5; } else { return error(Diagnostic.expected("0 or 1", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("0 or 1", input)); } } if (step == 5) { if (input.isCont()) { c = input.head(); if (c == '.') { input = input.step(); step = 6; } else { step = 9; } } else if (input.isDone()) { step = 9; } } while (step >= 6 && step <= 8) { if (input.isCont()) { c = input.head(); if (Base10.isDigit(c)) { input = input.step(); significand = 10 * significand + Base10.decodeDigit(c); exponent += 1; step += 1; continue; } else { step = 9; } } else if (input.isDone()) { step = 9; } break; } if (step == 9) { float weight = (float) significand; while (exponent > 0) { weight /= 10f; exponent -= 1; } if (weight <= 1f) { return done(weight); } else { return error(Diagnostic.message("invalid qvalue: " + weight, input)); } } if (input.isError()) { return error(input.trap()); } return new QValueParser(significand, exponent, step); } public static Parser<Float> parse(Input input) { return parse(input, 0, 0, 1); } public static Parser<Float> parseRest(Input input) { return parse(input, 0, 0, 3); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/QValueWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class QValueWriter extends Writer<Object, Object> { final int weight; final int step; QValueWriter(int weight, int step) { this.weight = weight; this.step = step; } QValueWriter(float weight) { if (weight < 0f || weight > 1f) { throw new HttpException("invalid qvalue: " + weight); } this.weight = (int) (weight * 1000f); this.step = 1; } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.weight, this.step); } static Writer<Object, Object> write(Output<?> output, int weight, int step) { if (step == 1 && output.isCont()) { output = output.write(';'); step = 2; } if (step == 2 && output.isCont()) { output = output.write(' '); step = 3; } if (step == 3 && output.isCont()) { output = output.write('q'); step = 4; } if (step == 4 && output.isCont()) { output = output.write('='); step = 5; } if (step == 5 && output.isCont()) { output = output.write('0' + (weight / 1000)); weight %= 1000; if (weight == 0) { return done(); } else { step = 6; } } if (step == 6 && output.isCont()) { output = output.write('.'); step = 7; } if (step == 7 && output.isCont()) { output = output.write('0' + (weight / 100)); weight %= 100; if (weight == 0) { return done(); } else { step = 8; } } if (step == 8 && output.isCont()) { output = output.write('0' + (weight / 10)); weight %= 10; if (weight == 0) { return done(); } else { step = 9; } } if (step == 9 && output.isCont()) { output = output.write('0' + weight); return done(); } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new QValueWriter(weight, step); } static Writer<Object, Object> write(Output<?> output, float weight) { if (weight >= 0f && weight <= 1f) { return write(output, (int) (weight * 1000f), 1); } else { return error(new HttpException("invalid qvalue: " + weight)); } } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/QuotedWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class QuotedWriter extends Writer<Object, Object> { final String quoted; final int index; final int escape; final int step; QuotedWriter(String quoted, int index, int escape, int step) { this.quoted = quoted; this.index = index; this.escape = escape; this.step = step; } QuotedWriter(String quoted) { this(quoted, 0, 0, 1); } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.quoted, this.index, this.escape, this.step); } static Writer<Object, Object> write(Output<?> output, String quoted, int index, int escape, int step) { final int length = quoted.length(); if (step == 1 && output.isCont()) { output = output.write('"'); step = 2; } do { if (step == 2 && output.isCont()) { if (index < length) { final int c = quoted.codePointAt(index); if (Http.isQuotedChar(c)) { output = output.write(c); } else if (Http.isVisibleChar(c)) { output = output.write('\\'); escape = c; step = 3; } else { return error(new HttpException("invalid quoted: " + quoted)); } index = quoted.offsetByCodePoints(index, 1); continue; } else { step = 4; break; } } if (step == 3 && output.isCont()) { output = output.write(escape); escape = 0; step = 2; continue; } break; } while (true); if (step == 4 && output.isCont()) { output = output.write('"'); return done(); } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new QuotedWriter(quoted, index, escape, step); } static Writer<Object, Object> write(Output<?> output, String quoted) { return write(output, quoted, 0, 0, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/TokenListParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.collections.FingerTrieSeq; import swim.util.Builder; final class TokenListParser extends Parser<FingerTrieSeq<String>> { final StringBuilder token; final Builder<String, FingerTrieSeq<String>> tokens; final int step; TokenListParser(StringBuilder token, Builder<String, FingerTrieSeq<String>> tokens, int step) { this.token = token; this.tokens = tokens; this.step = step; } @Override public Parser<FingerTrieSeq<String>> feed(Input input) { return parse(input, this.token, this.tokens, this.step); } static Parser<FingerTrieSeq<String>> parse(Input input, StringBuilder token, Builder<String, FingerTrieSeq<String>> tokens, int step) { int c = 0; if (step == 1) { if (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); token = new StringBuilder(); token.appendCodePoint(c); step = 2; } else { return done(FingerTrieSeq.<String>empty()); } } else if (input.isDone()) { return done(FingerTrieSeq.<String>empty()); } } if (step == 2) { while (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); token.appendCodePoint(c); } else { break; } } if (!input.isEmpty()) { if (tokens == null) { tokens = FingerTrieSeq.builder(); } tokens.add(token.toString()); token = null; step = 3; } } do { if (step == 3) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont() && c == ',') { input = input.step(); step = 4; } else if (!input.isEmpty()) { return done(tokens.bind()); } } if (step == 4) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (Http.isTokenChar(c)) { input = input.step(); token = new StringBuilder(); token.appendCodePoint(c); step = 5; } else { return error(Diagnostic.expected("token", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("token", input)); } } if (step == 5) { while (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); token.appendCodePoint(c); } else { break; } } if (!input.isEmpty()) { tokens.add(token.toString()); token = null; step = 3; continue; } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new TokenListParser(token, tokens, step); } static Parser<FingerTrieSeq<String>> parse(Input input) { return parse(input, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/TokenListWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import java.util.Iterator; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class TokenListWriter extends Writer<Object, Object> { final Iterator<?> tokens; final String token; final int index; final int step; TokenListWriter(Iterator<?> tokens, String token, int index, int step) { this.tokens = tokens; this.token = token; this.index = index; this.step = step; } TokenListWriter(Iterator<?> tokens) { this(tokens, null, 0, 1); } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.tokens, this.token, this.index, this.step); } static Writer<Object, Object> write(Output<?> output, Iterator<?> tokens, String token, int index, int step) { do { if (step == 1) { if (token == null) { if (!tokens.hasNext()) { return done(); } else { token = tokens.next().toString(); } } final int length = token.length(); if (length == 0) { return error(new HttpException("empty token")); } while (index < length && output.isCont()) { final int c = token.codePointAt(index); if (Http.isTokenChar(c)) { output = output.write(c); } else { return error(new HttpException("invalid token: " + token)); } index = token.offsetByCodePoints(index, 1); } if (index == length) { token = null; index = 0; if (!tokens.hasNext()) { return done(); } else { step = 2; } } } if (step == 2 && output.isCont()) { output = output.write(','); step = 3; } if (step == 3 && output.isCont()) { output = output.write(' '); step = 1; continue; } break; } while (true); if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new TokenListWriter(tokens, token, index, step); } static Writer<Object, Object> write(Output<?> output, Iterator<?> tokens) { return write(output, tokens, null, 0, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/TokenWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class TokenWriter extends Writer<Object, String> { final String token; final int index; TokenWriter(String token, int index) { this.token = token; this.index = index; } TokenWriter(String token) { this(token, 0); } @Override public Writer<Object, String> pull(Output<?> output) { return write(output, this.token, this.index); } static Writer<Object, String> write(Output<?> output, String token, int index) { final int length = token.length(); if (length == 0) { return error(new HttpException("empty token")); } while (index < length && output.isCont()) { final int c = token.codePointAt(index); if (Http.isTokenChar(c)) { output = output.write(c); index = token.offsetByCodePoints(index, 1); } else { return error(new HttpException("invalid token: " + token)); } } if (index >= length) { return done(); } else if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new TokenWriter(token, index); } static Writer<Object, String> write(Output<?> output, String token) { return write(output, token, 0); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/TransferCoding.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Debug; import swim.codec.Format; import swim.codec.Output; import swim.codec.Writer; import swim.collections.HashTrieMap; import swim.util.Murmur3; public final class TransferCoding extends HttpPart implements Debug { final String name; final HashTrieMap<String, String> params; TransferCoding(String name, HashTrieMap<String, String> params) { this.name = name; this.params = params; } TransferCoding(String name) { this(name, HashTrieMap.<String, String>empty()); } public String name() { return this.name; } public HashTrieMap<String, String> params() { return this.params; } public String getParam(String key) { return this.params.get(key); } public TransferCoding param(String key, String value) { return from(this.name, this.params.updated(key, value)); } public boolean isChunked() { return "chunked".equals(this.name); } public boolean isCompress() { return "compress".equals(this.name); } public boolean isDeflate() { return "deflate".equals(this.name); } public boolean isGzip() { return "gzip".equals(this.name); } @Override public Writer<?, ?> httpWriter(HttpWriter http) { return http.transferCodingWriter(this.name, this.params); } @Override public Writer<?, ?> writeHttp(Output<?> output, HttpWriter http) { return http.writeTransferCoding(this.name, this.params, output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof TransferCoding) { final TransferCoding that = (TransferCoding) other; return this.name.equals(that.name) && this.params.equals(that.params); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(TransferCoding.class); } return Murmur3.mash(Murmur3.mix(Murmur3.mix(hashSeed, this.name.hashCode()), this.params.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("TransferCoding").write('.').write("from").write('(') .debug(this.name).write(')'); for (HashTrieMap.Entry<String, String> param : this.params) { output = output.write('.').write("param").write('(') .debug(param.getKey()).write(", ").debug(param.getValue()).write(')'); } } @Override public String toString() { return Format.debug(this); } private static int hashSeed; private static TransferCoding chunked; private static TransferCoding compress; private static TransferCoding deflate; private static TransferCoding gzip; public static TransferCoding chunked() { if (chunked == null) { chunked = new TransferCoding("chunked"); } return chunked; } public static TransferCoding compress() { if (compress == null) { compress = new TransferCoding("compress"); } return compress; } public static TransferCoding deflate() { if (deflate == null) { deflate = new TransferCoding("deflate"); } return deflate; } public static TransferCoding gzip() { if (gzip == null) { gzip = new TransferCoding("gzip"); } return gzip; } public static TransferCoding from(String name, HashTrieMap<String, String> params) { if (params.isEmpty()) { if ("chunked".equals(name)) { return chunked(); } else if ("compress".equals(name)) { return compress(); } else if ("deflate".equals(name)) { return deflate(); } else if ("gzip".equals(name)) { return gzip(); } } return new TransferCoding(name, params); } public static TransferCoding from(String name) { return from(name, HashTrieMap.<String, String>empty()); } public static TransferCoding parse(String string) { return Http.standardParser().parseTransferCodingString(string); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/TransferCodingParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.collections.HashTrieMap; final class TransferCodingParser extends Parser<TransferCoding> { final HttpParser http; final StringBuilder name; final Parser<HashTrieMap<String, String>> params; final int step; TransferCodingParser(HttpParser http, StringBuilder name, Parser<HashTrieMap<String, String>> params, int step) { this.http = http; this.name = name; this.params = params; this.step = step; } TransferCodingParser(HttpParser http) { this(http, null, null, 1); } @Override public Parser<TransferCoding> feed(Input input) { return parse(input, this.http, this.name, this.params, this.step); } static Parser<TransferCoding> parse(Input input, HttpParser http, StringBuilder name, Parser<HashTrieMap<String, String>> params, int step) { int c = 0; if (step == 1) { if (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); if (name == null) { name = new StringBuilder(); } name.appendCodePoint(c); step = 2; } else { return error(Diagnostic.expected("transfer coding", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("transfer coding", input)); } } if (step == 2) { while (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); name.appendCodePoint(c); } else { break; } } if (input.isCont()) { step = 3; } else if (input.isDone()) { return done(http.transferCoding(name.toString(), HashTrieMap.<String, String>empty())); } } if (step == 3) { if (params == null) { params = http.parseParamMap(input); } else { params = params.feed(input); } if (params.isDone()) { return done(http.transferCoding(name.toString(), params.bind())); } else if (params.isError()) { return params.asError(); } } if (input.isError()) { return error(input.trap()); } return new TransferCodingParser(http, name, params, step); } static Parser<TransferCoding> parse(Input input, HttpParser http) { return parse(input, http, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/TransferCodingWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; import swim.collections.HashTrieMap; final class TransferCodingWriter extends Writer<Object, Object> { final HttpWriter http; final String name; final HashTrieMap<String, String> params; final Writer<?, ?> part; final int step; TransferCodingWriter(HttpWriter http, String name, HashTrieMap<String, String> params, Writer<?, ?> part, int step) { this.http = http; this.name = name; this.params = params; this.part = part; this.step = step; } TransferCodingWriter(HttpWriter http, String name, HashTrieMap<String, String> params) { this(http, name, params, null, 1); } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.http, this.name, this.params, this.part, this.step); } static Writer<Object, Object> write(Output<?> output, HttpWriter http, String name, HashTrieMap<String, String> params, Writer<?, ?> part, int step) { if (step == 1) { if (part == null) { part = http.writeToken(name, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; if (params.isEmpty()) { return done(); } else { step = 2; } } else if (part.isError()) { return part.asError(); } } if (step == 2) { if (part == null) { part = http.writeParamMap(params.iterator(), output); } else { part = part.pull(output); } if (part.isDone()) { return done(); } else if (part.isError()) { return part.asError(); } } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new TransferCodingWriter(http, name, params, part, step); } static Writer<Object, Object> write(Output<?> output, HttpWriter http, String name, HashTrieMap<String, String> params) { return write(output, http, name, params, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/UpgradeProtocol.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Debug; import swim.codec.Format; import swim.codec.Output; import swim.codec.Writer; import swim.util.Murmur3; public final class UpgradeProtocol extends HttpPart implements Debug { final String name; final String version; UpgradeProtocol(String name, String version) { this.name = name; this.version = version; } public String name() { return this.name; } public String version() { return this.version; } @Override public Writer<?, ?> httpWriter(HttpWriter http) { return http.upgradeProtocolWriter(this.name, this.version); } @Override public Writer<?, ?> writeHttp(Output<?> output, HttpWriter http) { return http.writeUpgradeProtocol(this.name, this.version, output); } public boolean matches(UpgradeProtocol that) { if (this == that) { return true; } else { return this.name.equalsIgnoreCase(that.name) && this.version.equals(that.version); } } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof UpgradeProtocol) { final UpgradeProtocol that = (UpgradeProtocol) other; return this.name.equals(that.name) && this.version.equals(that.version); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(UpgradeProtocol.class); } return Murmur3.mash(Murmur3.mix(Murmur3.mix(hashSeed, this.name.hashCode()), this.version.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("UpgradeProtocol").write('.').write("from").write('(').debug(this.name); if (!this.version.isEmpty()) { output = output.write(", ").debug(this.version); } output = output.write(')'); } @Override public String toString() { return Format.debug(this); } private static int hashSeed; private static UpgradeProtocol websocket; public static UpgradeProtocol websocket() { if (websocket == null) { websocket = new UpgradeProtocol("websocket", ""); } return websocket; } public static UpgradeProtocol from(String name, String version) { if ("".equals(version)) { return from(name); } else { return new UpgradeProtocol(name, version); } } public static UpgradeProtocol from(String name) { if ("websocket".equals(name)) { return websocket(); } else { return new UpgradeProtocol(name, ""); } } public static UpgradeProtocol parse(String string) { return Http.standardParser().parseUpgradeProtocolString(string); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/UpgradeProtocolParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; final class UpgradeProtocolParser extends Parser<UpgradeProtocol> { final HttpParser http; final StringBuilder name; final StringBuilder version; final int step; UpgradeProtocolParser(HttpParser http, StringBuilder name, StringBuilder version, int step) { this.http = http; this.name = name; this.version = version; this.step = step; } UpgradeProtocolParser(HttpParser http) { this(http, null, null, 1); } @Override public Parser<UpgradeProtocol> feed(Input input) { return parse(input, this.http, this.name, this.version, this.step); } static Parser<UpgradeProtocol> parse(Input input, HttpParser http, StringBuilder name, StringBuilder version, int step) { int c = 0; if (step == 1) { if (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); if (name == null) { name = new StringBuilder(); } name.appendCodePoint(c); step = 2; } else { return error(Diagnostic.expected("upgrade protocol name", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("upgrade protocol name", input)); } } if (step == 2) { while (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); name.appendCodePoint(c); } else { break; } } if (input.isCont() && c == '/') { input = input.step(); step = 3; } else if (!input.isEmpty()) { return done(http.upgradeProtocol(name.toString(), "")); } } if (step == 3) { if (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); if (version == null) { version = new StringBuilder(); } version.appendCodePoint(c); step = 4; } else { return error(Diagnostic.expected("upgrade protocol version", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("upgrade protocol version", input)); } } if (step == 4) { while (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); version.appendCodePoint(c); } else { break; } } if (!input.isEmpty()) { return done(http.upgradeProtocol(name.toString(), version.toString())); } } if (input.isError()) { return error(input.trap()); } return new UpgradeProtocolParser(http, name, version, step); } static Parser<UpgradeProtocol> parse(Input input, HttpParser http) { return parse(input, http, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/UpgradeProtocolWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class UpgradeProtocolWriter extends Writer<Object, Object> { final HttpWriter http; final String name; final String version; final Writer<?, ?> part; final int step; UpgradeProtocolWriter(HttpWriter http, String name, String version, Writer<?, ?> part, int step) { this.http = http; this.name = name; this.version = version; this.part = part; this.step = step; } UpgradeProtocolWriter(HttpWriter http, String name, String version) { this(http, name, version, null, 1); } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.http, this.name, this.version, this.part, this.step); } static Writer<Object, Object> write(Output<?> output, HttpWriter http, String name, String version, Writer<?, ?> part, int step) { if (step == 1) { if (part == null) { part = http.writeToken(name, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; if (version.isEmpty()) { return done(); } else { step = 2; } } else if (part.isError()) { return part.asError(); } } if (step == 2 && output.isCont()) { output = output.write('/'); step = 3; } if (step == 3) { if (part == null) { part = http.writeToken(version, output); } else { part = part.pull(output); } if (part.isDone()) { return done(); } else if (part.isError()) { return part.asError(); } } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new UpgradeProtocolWriter(http, name, version, part, step); } static Writer<Object, Object> write(Output<?> output, HttpWriter http, String name, String version) { return write(output, http, name, version, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/WebSocketExtension.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Debug; import swim.codec.Format; import swim.codec.Output; import swim.codec.Writer; import swim.collections.FingerTrieSeq; import swim.util.Murmur3; public final class WebSocketExtension extends HttpPart implements Debug { final String name; final FingerTrieSeq<WebSocketParam> params; WebSocketExtension(String name, FingerTrieSeq<WebSocketParam> params) { this.name = name; this.params = params; } public String name() { return this.name; } public FingerTrieSeq<WebSocketParam> params() { return this.params; } public WebSocketExtension param(WebSocketParam param) { return new WebSocketExtension(this.name, this.params.appended(param)); } public WebSocketExtension param(String key, String value) { return param(WebSocketParam.from(key, value)); } public WebSocketExtension param(String key) { return param(WebSocketParam.from(key)); } @Override public Writer<?, ?> httpWriter(HttpWriter http) { return http.webSocketExtensionWriter(this.name, this.params.iterator()); } @Override public Writer<?, ?> writeHttp(Output<?> output, HttpWriter http) { return http.writeWebSocketExtension(this.name, this.params.iterator(), output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof WebSocketExtension) { final WebSocketExtension that = (WebSocketExtension) other; return this.name.equals(that.name) && this.params.equals(that.params); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(WebSocketExtension.class); } return Murmur3.mash(Murmur3.mix(Murmur3.mix(hashSeed, this.name.hashCode()), this.params.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("WebSocketExtension").write('.').write("from").write('(') .debug(this.name).write(')'); for (WebSocketParam param : this.params) { output = output.write('.').write("param").write('(').debug(param.key); if (!param.value.isEmpty()) { output = output.write(", ").debug(param.value); } output = output.write(')'); } } @Override public String toString() { return Format.debug(this); } private static int hashSeed; public static WebSocketExtension permessageDeflate(boolean serverNoContextTakeover, boolean clientNoContextTakeover, int serverMaxWindowBits, int clientMaxWindowBits) { FingerTrieSeq<WebSocketParam> params = FingerTrieSeq.empty(); if (serverNoContextTakeover) { params = params.appended(WebSocketParam.serverNoContextTakeover()); } if (clientNoContextTakeover) { params = params.appended(WebSocketParam.clientNoContextTakeover()); } if (serverMaxWindowBits != 15) { params = params.appended(WebSocketParam.serverMaxWindowBits(serverMaxWindowBits)); } if (clientMaxWindowBits == 0) { params = params.appended(WebSocketParam.clientMaxWindowBits()); } else if (clientMaxWindowBits != 15) { params = params.appended(WebSocketParam.clientMaxWindowBits(clientMaxWindowBits)); } return new WebSocketExtension("permessage-deflate", params); } public static WebSocketExtension from(String name, FingerTrieSeq<WebSocketParam> params) { return new WebSocketExtension(name, params); } public static WebSocketExtension from(String name, WebSocketParam... params) { return new WebSocketExtension(name, FingerTrieSeq.of(params)); } public static WebSocketExtension from(String name) { return new WebSocketExtension(name, FingerTrieSeq.<WebSocketParam>empty()); } public static WebSocketExtension parse(String string) { return Http.standardParser().parseWebSocketExtensionString(string); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/WebSocketExtensionParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.collections.FingerTrieSeq; import swim.util.Builder; final class WebSocketExtensionParser extends Parser<WebSocketExtension> { final HttpParser http; final StringBuilder name; final Parser<WebSocketParam> param; final Builder<WebSocketParam, FingerTrieSeq<WebSocketParam>> params; final int step; WebSocketExtensionParser(HttpParser http, StringBuilder name, Parser<WebSocketParam> param, Builder<WebSocketParam, FingerTrieSeq<WebSocketParam>> params, int step) { this.http = http; this.name = name; this.param = param; this.params = params; this.step = step; } WebSocketExtensionParser(HttpParser http) { this(http, null, null, null, 1); } @Override public Parser<WebSocketExtension> feed(Input input) { return parse(input, this.http, this.name, this.param, this.params, this.step); } static Parser<WebSocketExtension> parse(Input input, HttpParser http, StringBuilder name, Parser<WebSocketParam> param, Builder<WebSocketParam, FingerTrieSeq<WebSocketParam>> params, int step) { int c = 0; if (step == 1) { if (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); if (name == null) { name = new StringBuilder(); } name.appendCodePoint(c); step = 2; } else { return error(Diagnostic.expected("websocket extension", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("websocket extension", input)); } } if (step == 2) { while (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); name.appendCodePoint(c); } else { break; } } if (!input.isEmpty()) { step = 3; } } do { if (step == 3) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont() && c == ';') { if (params == null) { params = FingerTrieSeq.builder(); } input = input.step(); step = 4; } else if (!input.isEmpty()) { return done(http.webSocketExtension(name.toString(), params != null ? params.bind() : FingerTrieSeq.<WebSocketParam>empty())); } } if (step == 4) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (!input.isEmpty()) { step = 5; } } if (step == 5) { if (param == null) { param = http.parseWebSocketParam(input); } else { param = param.feed(input); } if (param.isDone()) { params.add(param.bind()); param = null; step = 3; continue; } else if (param.isError()) { return param.asError(); } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new WebSocketExtensionParser(http, name, param, params, step); } static Parser<WebSocketExtension> parse(Input input, HttpParser http) { return parse(input, http, null, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/WebSocketExtensionWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import java.util.Iterator; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; final class WebSocketExtensionWriter extends Writer<Object, Object> { final HttpWriter http; final String name; final Iterator<WebSocketParam> params; final Writer<?, ?> part; final int step; WebSocketExtensionWriter(HttpWriter http, String name, Iterator<WebSocketParam> params, Writer<?, ?> part, int step) { this.http = http; this.name = name; this.params = params; this.part = part; this.step = step; } WebSocketExtensionWriter(HttpWriter http, String name, Iterator<WebSocketParam> params) { this(http, name, params, null, 1); } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.http, this.name, this.params, this.part, this.step); } static Writer<Object, Object> write(Output<?> output, HttpWriter http, String name, Iterator<WebSocketParam> params, Writer<?, ?> part, int step) { if (step == 1) { if (part == null) { part = http.writeToken(name, output); } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 2; } else if (part.isError()) { return part.asError(); } } do { if (step == 2) { if (!params.hasNext()) { return done(); } else if (output.isCont()) { output = output.write(';'); step = 3; } } if (step == 3 && output.isCont()) { output = output.write(' '); step = 4; } if (step == 4) { if (part == null) { part = params.next().writeHttp(output, http); } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 2; continue; } else if (part.isError()) { return part.asError(); } } break; } while (true); if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new WebSocketExtensionWriter(http, name, params, part, step); } static Writer<Object, Object> write(Output<?> output, HttpWriter http, String name, Iterator<WebSocketParam> params) { return write(output, http, name, params, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/WebSocketParam.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Debug; import swim.codec.Format; import swim.codec.Output; import swim.codec.Writer; import swim.util.Murmur3; public final class WebSocketParam extends HttpPart implements Debug { final String key; final String value; WebSocketParam(String key, String value) { this.key = key; this.value = value; } public String key() { return this.key; } public String value() { return this.value; } public Writer<?, ?> httpWriter(HttpWriter http) { return http.webSocketParamWriter(this.key, this.value); } @Override public Writer<?, ?> writeHttp(Output<?> output, HttpWriter http) { return http.writeWebSocketParam(this.key, this.value, output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof WebSocketParam) { final WebSocketParam that = (WebSocketParam) other; return this.key.equals(that.key) && this.value.equals(that.value); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(WebSocketParam.class); } return Murmur3.mash(Murmur3.mix(Murmur3.mix(hashSeed, this.key.hashCode()), this.value.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("WebSocketParam").write('.').write("from").write('(').debug(this.key); if (!this.value.isEmpty()) { output = output.write(", ").debug(this.value); } output = output.write(')'); } @Override public String toString() { return Format.debug(this); } private static int hashSeed; private static WebSocketParam serverNoContextTakeover; private static WebSocketParam clientNoContextTakeover; private static WebSocketParam clientMaxWindowBits; public static WebSocketParam serverMaxWindowBits(int maxWindowBits) { return new WebSocketParam("server_max_window_bits", Integer.toString(maxWindowBits)); } public static WebSocketParam clientMaxWindowBits(int maxWindowBits) { return new WebSocketParam("client_max_window_bits", Integer.toString(maxWindowBits)); } public static WebSocketParam clientMaxWindowBits() { if (clientMaxWindowBits == null) { clientMaxWindowBits = new WebSocketParam("client_max_window_bits", ""); } return clientMaxWindowBits; } public static WebSocketParam serverNoContextTakeover() { if (serverNoContextTakeover == null) { serverNoContextTakeover = new WebSocketParam("server_no_context_takeover", ""); } return serverNoContextTakeover; } public static WebSocketParam clientNoContextTakeover() { if (clientNoContextTakeover == null) { clientNoContextTakeover = new WebSocketParam("client_no_context_takeover", ""); } return clientNoContextTakeover; } public static WebSocketParam from(String key, String value) { if ("".equals(value)) { return from(key); } else { return new WebSocketParam(key, value); } } public static WebSocketParam from(String key) { if ("server_no_context_takeover".equals(key)) { return serverNoContextTakeover(); } else if ("client_no_context_takeover".equals(key)) { return clientNoContextTakeover(); } else { return new WebSocketParam(key, ""); } } public static WebSocketParam parse(String string) { return Http.standardParser().parseWebSocketParamString(string); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/WebSocketParamParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; final class WebSocketParamParser extends Parser<WebSocketParam> { final HttpParser http; final StringBuilder key; final StringBuilder value; final int step; WebSocketParamParser(HttpParser http, StringBuilder key, StringBuilder value, int step) { this.http = http; this.key = key; this.value = value; this.step = step; } WebSocketParamParser(HttpParser http) { this(http, null, null, 1); } @Override public Parser<WebSocketParam> feed(Input input) { return parse(input, this.http, this.key, this.value, this.step); } static Parser<WebSocketParam> parse(Input input, HttpParser http, StringBuilder key, StringBuilder value, int step) { int c = 0; if (step == 1) { if (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); if (key == null) { key = new StringBuilder(); } key.appendCodePoint(c); step = 2; } else { return error(Diagnostic.expected("param name", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("param name", input)); } } if (step == 2) { while (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); key.appendCodePoint(c); } else { break; } } if (!input.isEmpty()) { step = 3; } } if (step == 3) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont() && c == '=') { input = input.step(); step = 4; } else if (!input.isEmpty()) { return done(http.webSocketParam(key.toString(), "")); } } if (step == 4) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { if (value == null) { value = new StringBuilder(); } if (c == '"') { input = input.step(); step = 7; } else { step = 5; } } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } if (step == 5) { if (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); value.appendCodePoint(c); step = 6; } else { return error(Diagnostic.expected("param value", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("param value", input)); } } if (step == 6) { while (input.isCont()) { c = input.head(); if (Http.isTokenChar(c)) { input = input.step(); value.appendCodePoint(c); } else { break; } } if (!input.isEmpty()) { return done(http.webSocketParam(key.toString(), value.toString())); } } do { if (step == 7) { while (input.isCont()) { c = input.head(); if (Http.isQuotedChar(c)) { input = input.step(); value.appendCodePoint(c); } else { break; } } if (input.isCont()) { if (c == '"') { input = input.step(); return done(http.webSocketParam(key.toString(), value.toString())); } else if (c == '\\') { input = input.step(); step = 8; } else { return error(Diagnostic.unexpected(input)); } } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } if (step == 8) { if (input.isCont()) { c = input.head(); if (Http.isEscapeChar(c)) { input = input.step(); value.appendCodePoint(c); step = 7; continue; } else { return error(Diagnostic.expected("escape character", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("escape character", input)); } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new WebSocketParamParser(http, key, value, step); } static Parser<WebSocketParam> parse(Input input, HttpParser http) { return parse(input, http, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim
java-sources/ai/swim/swim-http/3.10.0/swim/http/package-info.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. /** * HTTP wire protocol model, decoders, and encoders. */ package swim.http;
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/Accept.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Writer; import swim.collections.FingerTrieSeq; import swim.http.HttpHeader; import swim.http.HttpParser; import swim.http.HttpWriter; import swim.http.MediaRange; import swim.util.Builder; import swim.util.Murmur3; public final class Accept extends HttpHeader { final FingerTrieSeq<MediaRange> mediaRanges; Accept(FingerTrieSeq<MediaRange> mediaRanges) { this.mediaRanges = mediaRanges; } @Override public String lowerCaseName() { return "accept"; } @Override public String name() { return "Accept"; } public FingerTrieSeq<MediaRange> mediaRanges() { return this.mediaRanges; } @Override public Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http) { return http.writeParamList(this.mediaRanges.iterator(), output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof Accept) { final Accept that = (Accept) other; return this.mediaRanges.equals(that.mediaRanges); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(Accept.class); } return Murmur3.mash(Murmur3.mix(hashSeed, this.mediaRanges.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("Accept").write('.').write("from").write('('); final int n = this.mediaRanges.size(); if (n > 0) { output.debug(this.mediaRanges.head()); for (int i = 1; i < n; i += 1) { output = output.write(", ").debug(this.mediaRanges.get(i)); } } output = output.write(')'); } private static int hashSeed; public static Accept from(FingerTrieSeq<MediaRange> mediaRanges) { return new Accept(mediaRanges); } public static Accept from(MediaRange... mediaRanges) { return new Accept(FingerTrieSeq.of(mediaRanges)); } public static Accept from(String... mediaRangeStrings) { final Builder<MediaRange, FingerTrieSeq<MediaRange>> mediaRanges = FingerTrieSeq.builder(); for (int i = 0, n = mediaRangeStrings.length; i < n; i += 1) { mediaRanges.add(MediaRange.parse(mediaRangeStrings[i])); } return new Accept(mediaRanges.bind()); } public static Parser<Accept> parseHttpValue(Input input, HttpParser http) { return AcceptParser.parse(input, http); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/AcceptCharset.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Writer; import swim.collections.FingerTrieSeq; import swim.http.HttpCharset; import swim.http.HttpHeader; import swim.http.HttpParser; import swim.http.HttpWriter; import swim.util.Builder; import swim.util.Murmur3; public final class AcceptCharset extends HttpHeader { final FingerTrieSeq<HttpCharset> charsets; AcceptCharset(FingerTrieSeq<HttpCharset> charsets) { this.charsets = charsets; } @Override public boolean isBlank() { return this.charsets.isEmpty(); } @Override public String lowerCaseName() { return "accept-charset"; } @Override public String name() { return "Accept-Charset"; } public FingerTrieSeq<HttpCharset> charsets() { return this.charsets; } @Override public Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http) { return http.writeParamList(this.charsets.iterator(), output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof AcceptCharset) { final AcceptCharset that = (AcceptCharset) other; return this.charsets.equals(that.charsets); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(AcceptCharset.class); } return Murmur3.mash(Murmur3.mix(hashSeed, this.charsets.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("AcceptCharset").write('.').write("from").write('('); final int n = this.charsets.size(); if (n > 0) { output.debug(this.charsets.head()); for (int i = 1; i < n; i += 1) { output = output.write(", ").debug(this.charsets.get(i)); } } output = output.write(')'); } private static int hashSeed; public static AcceptCharset from(FingerTrieSeq<HttpCharset> charsets) { return new AcceptCharset(charsets); } public static AcceptCharset from(HttpCharset... charsets) { return new AcceptCharset(FingerTrieSeq.of(charsets)); } public static AcceptCharset from(String... charsetStrings) { final Builder<HttpCharset, FingerTrieSeq<HttpCharset>> charsets = FingerTrieSeq.builder(); for (int i = 0, n = charsetStrings.length; i < n; i += 1) { charsets.add(HttpCharset.parse(charsetStrings[i])); } return new AcceptCharset(charsets.bind()); } public static Parser<AcceptCharset> parseHttpValue(Input input, HttpParser http) { return AcceptCharsetParser.parse(input, http); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/AcceptCharsetParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.collections.FingerTrieSeq; import swim.http.Http; import swim.http.HttpCharset; import swim.http.HttpParser; import swim.util.Builder; final class AcceptCharsetParser extends Parser<AcceptCharset> { final HttpParser http; final Parser<HttpCharset> charset; final Builder<HttpCharset, FingerTrieSeq<HttpCharset>> charsets; final int step; AcceptCharsetParser(HttpParser http, Parser<HttpCharset> charset, Builder<HttpCharset, FingerTrieSeq<HttpCharset>> charsets, int step) { this.http = http; this.charset = charset; this.charsets = charsets; this.step = step; } AcceptCharsetParser(HttpParser http) { this(http, null, null, 1); } @Override public Parser<AcceptCharset> feed(Input input) { return parse(input, this.http, this.charset, this.charsets, this.step); } static Parser<AcceptCharset> parse(Input input, HttpParser http, Parser<HttpCharset> charset, Builder<HttpCharset, FingerTrieSeq<HttpCharset>> charsets, int step) { int c = 0; if (step == 1) { if (charset == null) { charset = http.parseCharset(input); } else { charset = charset.feed(input); } if (charset.isDone()) { if (charsets == null) { charsets = FingerTrieSeq.builder(); } charsets.add(charset.bind()); charset = null; step = 2; } else if (charset.isError()) { return charset.asError(); } } do { if (step == 2) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont() && c == ',') { input = input.step(); step = 3; } else if (!input.isEmpty()) { return done(AcceptCharset.from(charsets.bind())); } } if (step == 3) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { step = 4; } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } if (step == 4) { if (charset == null) { charset = http.parseCharset(input); } else { charset = charset.feed(input); } if (charset.isDone()) { charsets.add(charset.bind()); charset = null; step = 2; continue; } else if (charset.isError()) { return charset.asError(); } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new AcceptCharsetParser(http, charset, charsets, step); } static Parser<AcceptCharset> parse(Input input, HttpParser http) { return parse(input, http, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/AcceptEncoding.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Writer; import swim.collections.FingerTrieSeq; import swim.http.ContentCoding; import swim.http.HttpHeader; import swim.http.HttpParser; import swim.http.HttpWriter; import swim.util.Builder; import swim.util.Murmur3; public final class AcceptEncoding extends HttpHeader { final FingerTrieSeq<ContentCoding> codings; AcceptEncoding(FingerTrieSeq<ContentCoding> codings) { this.codings = codings; } @Override public boolean isBlank() { return this.codings.isEmpty(); } @Override public String lowerCaseName() { return "accept-encoding"; } @Override public String name() { return "Accept-Encoding"; } public FingerTrieSeq<ContentCoding> codings() { return this.codings; } @Override public Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http) { return http.writeParamList(this.codings.iterator(), output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof AcceptEncoding) { final AcceptEncoding that = (AcceptEncoding) other; return this.codings.equals(that.codings); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(AcceptEncoding.class); } return Murmur3.mash(Murmur3.mix(hashSeed, this.codings.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("AcceptEncoding").write('.').write("from").write('('); final int n = this.codings.size(); if (n > 0) { output.debug(this.codings.head()); for (int i = 1; i < n; i += 1) { output = output.write(", ").debug(this.codings.get(i)); } } output = output.write(')'); } private static int hashSeed; public static AcceptEncoding from(FingerTrieSeq<ContentCoding> codings) { return new AcceptEncoding(codings); } public static AcceptEncoding from(ContentCoding... codings) { return new AcceptEncoding(FingerTrieSeq.of(codings)); } public static AcceptEncoding from(String... codingStrings) { final Builder<ContentCoding, FingerTrieSeq<ContentCoding>> codings = FingerTrieSeq.builder(); for (int i = 0, n = codingStrings.length; i < n; i += 1) { codings.add(ContentCoding.parse(codingStrings[i])); } return new AcceptEncoding(codings.bind()); } public static Parser<AcceptEncoding> parseHttpValue(Input input, HttpParser http) { return AcceptEncodingParser.parse(input, http); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/AcceptEncodingParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.collections.FingerTrieSeq; import swim.http.ContentCoding; import swim.http.Http; import swim.http.HttpParser; import swim.util.Builder; final class AcceptEncodingParser extends Parser<AcceptEncoding> { final HttpParser http; final Parser<ContentCoding> coding; final Builder<ContentCoding, FingerTrieSeq<ContentCoding>> codings; final int step; AcceptEncodingParser(HttpParser http, Parser<ContentCoding> coding, Builder<ContentCoding, FingerTrieSeq<ContentCoding>> codings, int step) { this.http = http; this.coding = coding; this.codings = codings; this.step = step; } AcceptEncodingParser(HttpParser http) { this(http, null, null, 1); } @Override public Parser<AcceptEncoding> feed(Input input) { return parse(input, this.http, this.coding, this.codings, this.step); } static Parser<AcceptEncoding> parse(Input input, HttpParser http, Parser<ContentCoding> coding, Builder<ContentCoding, FingerTrieSeq<ContentCoding>> codings, int step) { int c = 0; if (step == 1) { if (coding == null) { coding = http.parseContentCoding(input); } else { coding = coding.feed(input); } if (coding.isDone()) { if (codings == null) { codings = FingerTrieSeq.builder(); } codings.add(coding.bind()); coding = null; step = 2; } else if (coding.isError()) { return coding.asError(); } } do { if (step == 2) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont() && c == ',') { input = input.step(); step = 3; } else if (!input.isEmpty()) { return done(AcceptEncoding.from(codings.bind())); } } if (step == 3) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { step = 4; } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } if (step == 4) { if (coding == null) { coding = http.parseContentCoding(input); } else { coding = coding.feed(input); } if (coding.isDone()) { codings.add(coding.bind()); coding = null; step = 2; continue; } else if (coding.isError()) { return coding.asError(); } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new AcceptEncodingParser(http, coding, codings, step); } static Parser<AcceptEncoding> parse(Input input, HttpParser http) { return parse(input, http, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/AcceptLanguage.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Writer; import swim.collections.FingerTrieSeq; import swim.http.HttpHeader; import swim.http.HttpParser; import swim.http.HttpWriter; import swim.http.LanguageRange; import swim.util.Builder; import swim.util.Murmur3; public final class AcceptLanguage extends HttpHeader { final FingerTrieSeq<LanguageRange> languages; AcceptLanguage(FingerTrieSeq<LanguageRange> languages) { this.languages = languages; } @Override public boolean isBlank() { return this.languages.isEmpty(); } @Override public String lowerCaseName() { return "accept-language"; } @Override public String name() { return "Accept-Language"; } public FingerTrieSeq<LanguageRange> languages() { return this.languages; } @Override public Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http) { return http.writeParamList(this.languages.iterator(), output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof AcceptLanguage) { final AcceptLanguage that = (AcceptLanguage) other; return this.languages.equals(that.languages); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(AcceptLanguage.class); } return Murmur3.mash(Murmur3.mix(hashSeed, this.languages.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("AcceptLanguage").write('.').write("from").write('('); final int n = this.languages.size(); if (n > 0) { output.debug(this.languages.head()); for (int i = 1; i < n; i += 1) { output = output.write(", ").debug(this.languages.get(i)); } } output = output.write(')'); } private static int hashSeed; public static AcceptLanguage from(FingerTrieSeq<LanguageRange> languages) { return new AcceptLanguage(languages); } public static AcceptLanguage from(LanguageRange... languages) { return new AcceptLanguage(FingerTrieSeq.of(languages)); } public static AcceptLanguage from(String... languageStrings) { final Builder<LanguageRange, FingerTrieSeq<LanguageRange>> languages = FingerTrieSeq.builder(); for (int i = 0, n = languageStrings.length; i < n; i += 1) { languages.add(LanguageRange.parse(languageStrings[i])); } return new AcceptLanguage(languages.bind()); } public static Parser<AcceptLanguage> parseHttpValue(Input input, HttpParser http) { return AcceptLanguageParser.parse(input, http); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/AcceptLanguageParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.collections.FingerTrieSeq; import swim.http.Http; import swim.http.HttpParser; import swim.http.LanguageRange; import swim.util.Builder; final class AcceptLanguageParser extends Parser<AcceptLanguage> { final HttpParser http; final Parser<LanguageRange> language; final Builder<LanguageRange, FingerTrieSeq<LanguageRange>> languages; final int step; AcceptLanguageParser(HttpParser http, Parser<LanguageRange> language, Builder<LanguageRange, FingerTrieSeq<LanguageRange>> languages, int step) { this.http = http; this.language = language; this.languages = languages; this.step = step; } AcceptLanguageParser(HttpParser http) { this(http, null, null, 1); } @Override public Parser<AcceptLanguage> feed(Input input) { return parse(input, this.http, this.language, this.languages, this.step); } static Parser<AcceptLanguage> parse(Input input, HttpParser http, Parser<LanguageRange> language, Builder<LanguageRange, FingerTrieSeq<LanguageRange>> languages, int step) { int c = 0; if (step == 1) { if (language == null) { language = http.parseLanguageRange(input); } else { language = language.feed(input); } if (language.isDone()) { if (languages == null) { languages = FingerTrieSeq.builder(); } languages.add(language.bind()); language = null; step = 2; } else if (language.isError()) { return language.asError(); } } do { if (step == 2) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont() && c == ',') { input = input.step(); step = 3; } else if (!input.isEmpty()) { return done(AcceptLanguage.from(languages.bind())); } } if (step == 3) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { step = 4; } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } if (step == 4) { if (language == null) { language = http.parseLanguageRange(input); } else { language = language.feed(input); } if (language.isDone()) { languages.add(language.bind()); language = null; step = 2; continue; } else if (language.isError()) { return language.asError(); } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new AcceptLanguageParser(http, language, languages, step); } static Parser<AcceptLanguage> parse(Input input, HttpParser http) { return parse(input, http, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/AcceptParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.collections.FingerTrieSeq; import swim.http.Http; import swim.http.HttpParser; import swim.http.MediaRange; import swim.util.Builder; final class AcceptParser extends Parser<Accept> { final HttpParser http; final Parser<MediaRange> mediaRange; final Builder<MediaRange, FingerTrieSeq<MediaRange>> mediaRanges; final int step; AcceptParser(HttpParser http, Parser<MediaRange> mediaRange, Builder<MediaRange, FingerTrieSeq<MediaRange>> mediaRanges, int step) { this.http = http; this.mediaRange = mediaRange; this.mediaRanges = mediaRanges; this.step = step; } AcceptParser(HttpParser http) { this(http, null, null, 1); } @Override public Parser<Accept> feed(Input input) { return parse(input, this.http, this.mediaRange, this.mediaRanges, this.step); } static Parser<Accept> parse(Input input, HttpParser http, Parser<MediaRange> mediaRange, Builder<MediaRange, FingerTrieSeq<MediaRange>> mediaRanges, int step) { int c = 0; if (step == 1) { if (mediaRange == null) { mediaRange = http.parseMediaRange(input); } else { mediaRange = mediaRange.feed(input); } if (mediaRange.isDone()) { if (mediaRanges == null) { mediaRanges = FingerTrieSeq.builder(); } mediaRanges.add(mediaRange.bind()); mediaRange = null; step = 2; } else if (mediaRange.isError()) { return mediaRange.asError(); } } do { if (step == 2) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont() && c == ',') { input = input.step(); step = 3; } else if (!input.isEmpty()) { return done(Accept.from(mediaRanges.bind())); } } if (step == 3) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { step = 4; } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } if (step == 4) { if (mediaRange == null) { mediaRange = http.parseMediaRange(input); } else { mediaRange = mediaRange.feed(input); } if (mediaRange.isDone()) { mediaRanges.add(mediaRange.bind()); mediaRange = null; step = 2; continue; } else if (mediaRange.isError()) { return mediaRange.asError(); } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new AcceptParser(http, mediaRange, mediaRanges, step); } static Parser<Accept> parse(Input input, HttpParser http) { return parse(input, http, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/Allow.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Writer; import swim.collections.FingerTrieSeq; import swim.http.HttpHeader; import swim.http.HttpMethod; import swim.http.HttpParser; import swim.http.HttpWriter; import swim.util.Builder; import swim.util.Murmur3; public final class Allow extends HttpHeader { final FingerTrieSeq<HttpMethod> methods; Allow(FingerTrieSeq<HttpMethod> methods) { this.methods = methods; } @Override public boolean isBlank() { return this.methods.isEmpty(); } @Override public String lowerCaseName() { return "allow"; } @Override public String name() { return "Allow"; } public FingerTrieSeq<HttpMethod> methods() { return this.methods; } @Override public Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http) { return http.writeParamList(this.methods.iterator(), output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof Allow) { final Allow that = (Allow) other; return this.methods.equals(that.methods); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(Allow.class); } return Murmur3.mash(Murmur3.mix(hashSeed, this.methods.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("Allow").write('.').write("from").write('('); final int n = this.methods.size(); if (n > 0) { output.debug(this.methods.head()); for (int i = 1; i < n; i += 1) { output.debug(", ").debug(this.methods.get(i)); } } output = output.write(')'); } private static int hashSeed; public static Allow from(FingerTrieSeq<HttpMethod> methods) { return new Allow(methods); } public static Allow from(HttpMethod... methods) { return new Allow(FingerTrieSeq.of(methods)); } public static Allow from(String... methodStrings) { final Builder<HttpMethod, FingerTrieSeq<HttpMethod>> methods = FingerTrieSeq.builder(); for (int i = 0, n = methodStrings.length; i < n; i += 1) { methods.add(HttpMethod.parseHttp(methodStrings[i])); } return new Allow(methods.bind()); } public static Parser<Allow> parseHttpValue(Input input, HttpParser http) { return AllowParser.parse(input, http); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/AllowParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.collections.FingerTrieSeq; import swim.http.Http; import swim.http.HttpMethod; import swim.http.HttpParser; import swim.util.Builder; final class AllowParser extends Parser<Allow> { final HttpParser http; final Parser<HttpMethod> method; final Builder<HttpMethod, FingerTrieSeq<HttpMethod>> methods; final int step; AllowParser(HttpParser http, Parser<HttpMethod> method, Builder<HttpMethod, FingerTrieSeq<HttpMethod>> methods, int step) { this.http = http; this.method = method; this.methods = methods; this.step = step; } AllowParser(HttpParser http) { this(http, null, null, 1); } @Override public Parser<Allow> feed(Input input) { return parse(input, this.http, this.method, this.methods, this.step); } static Parser<Allow> parse(Input input, HttpParser http, Parser<HttpMethod> method, Builder<HttpMethod, FingerTrieSeq<HttpMethod>> methods, int step) { int c = 0; if (step == 1) { if (method == null) { method = http.parseMethod(input); } else { method = method.feed(input); } if (method.isDone()) { if (methods == null) { methods = FingerTrieSeq.builder(); } methods.add(method.bind()); method = null; step = 2; } else if (method.isError()) { return method.asError(); } } do { if (step == 2) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont() && c == ',') { input = input.step(); step = 3; } else if (!input.isEmpty()) { return done(Allow.from(methods.bind())); } } if (step == 3) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { step = 4; } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } if (step == 4) { if (method == null) { method = http.parseMethod(input); } else { method = method.feed(input); } if (method.isDone()) { methods.add(method.bind()); method = null; step = 2; continue; } else if (method.isError()) { return method.asError(); } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new AllowParser(http, method, methods, step); } static Parser<Allow> parse(Input input, HttpParser http) { return parse(input, http, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/Connection.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Writer; import swim.collections.FingerTrieSeq; import swim.http.HttpHeader; import swim.http.HttpParser; import swim.http.HttpWriter; import swim.util.Murmur3; public final class Connection extends HttpHeader { final FingerTrieSeq<String> options; Connection(FingerTrieSeq<String> options) { this.options = options; } @Override public boolean isBlank() { return this.options.isEmpty(); } @Override public String lowerCaseName() { return "connection"; } @Override public String name() { return "Connection"; } public FingerTrieSeq<String> options() { return this.options; } public boolean contains(String option) { final FingerTrieSeq<String> options = this.options; for (int i = 0, n = options.size(); i < n; i += 1) { if (option.equalsIgnoreCase(options.get(i))) { return true; } } return false; } @Override public Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http) { return http.writeTokenList(this.options.iterator(), output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof Connection) { final Connection that = (Connection) other; return this.options.equals(that.options); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(Connection.class); } return Murmur3.mash(Murmur3.mix(hashSeed, this.options.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("Connection").write('.').write("from").write('('); final int n = this.options.size(); if (n > 0) { output.debug(this.options.head()); for (int i = 1; i < n; i += 1) { output = output.write(", ").write(this.options.get(i)); } } output = output.write(')'); } private static int hashSeed; private static Connection close; private static Connection upgrade; public static Connection close() { if (close == null) { close = new Connection(FingerTrieSeq.of("close")); } return close; } public static Connection upgrade() { if (upgrade == null) { upgrade = new Connection(FingerTrieSeq.of("Upgrade")); } return upgrade; } public static Connection from(FingerTrieSeq<String> options) { if (options.size() == 1) { final String option = options.head(); if ("close".equals(option)) { return close(); } else if ("Upgrade".equals(option)) { return upgrade(); } } return new Connection(options); } public static Connection from(String... options) { return from(FingerTrieSeq.of(options)); } public static Parser<Connection> parseHttpValue(Input input, HttpParser http) { return ConnectionParser.parse(input, http); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/ConnectionParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.collections.FingerTrieSeq; import swim.http.HttpParser; final class ConnectionParser extends Parser<Connection> { final HttpParser http; final Parser<FingerTrieSeq<String>> options; ConnectionParser(HttpParser http, Parser<FingerTrieSeq<String>> options) { this.http = http; this.options = options; } ConnectionParser(HttpParser http) { this(http, null); } @Override public Parser<Connection> feed(Input input) { return parse(input, this.http, this.options); } static Parser<Connection> parse(Input input, HttpParser http, Parser<FingerTrieSeq<String>> options) { if (options == null) { options = http.parseTokenList(input); } else { options = options.feed(input); } if (options.isDone()) { final FingerTrieSeq<String> tokens = options.bind(); if (!tokens.isEmpty()) { return done(Connection.from(tokens)); } else { return error(Diagnostic.expected("connection option", input)); } } else if (options.isError()) { return options.asError(); } else if (input.isError()) { return error(input.trap()); } return new ConnectionParser(http, options); } static Parser<Connection> parse(Input input, HttpParser http) { return parse(input, http, null); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/ContentEncoding.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Writer; import swim.collections.FingerTrieSeq; import swim.http.HttpHeader; import swim.http.HttpParser; import swim.http.HttpWriter; import swim.util.Murmur3; public final class ContentEncoding extends HttpHeader { final FingerTrieSeq<String> codings; ContentEncoding(FingerTrieSeq<String> codings) { this.codings = codings; } @Override public boolean isBlank() { return this.codings.isEmpty(); } @Override public String lowerCaseName() { return "content-encoding"; } @Override public String name() { return "Content-Encoding"; } public FingerTrieSeq<String> codings() { return this.codings; } public boolean contains(String coding) { final FingerTrieSeq<String> codings = this.codings; for (int i = 0, n = codings.size(); i < n; i += 1) { if (coding.equalsIgnoreCase(codings.get(i))) { return true; } } return false; } @Override public Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http) { return http.writeTokenList(this.codings.iterator(), output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof ContentEncoding) { final ContentEncoding that = (ContentEncoding) other; return this.codings.equals(that.codings); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(ContentEncoding.class); } return Murmur3.mash(Murmur3.mix(hashSeed, this.codings.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("ContentEncoding").write('.').write("from").write('('); final int n = this.codings.size(); if (n > 0) { output.debug(this.codings.head()); for (int i = 1; i < n; i += 1) { output = output.write(", ").debug(this.codings.get(i)); } } output = output.write(')'); } private static int hashSeed; public static ContentEncoding from(FingerTrieSeq<String> codings) { return new ContentEncoding(codings); } public static ContentEncoding from(String... codings) { return new ContentEncoding(FingerTrieSeq.of(codings)); } public static Parser<ContentEncoding> parseHttpValue(Input input, HttpParser http) { return ContentEncodingParser.parse(input, http); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/ContentEncodingParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.collections.FingerTrieSeq; import swim.http.HttpParser; final class ContentEncodingParser extends Parser<ContentEncoding> { final HttpParser http; final Parser<FingerTrieSeq<String>> codings; ContentEncodingParser(HttpParser http, Parser<FingerTrieSeq<String>> codings) { this.http = http; this.codings = codings; } ContentEncodingParser(HttpParser http) { this(http, null); } @Override public Parser<ContentEncoding> feed(Input input) { return parse(input, this.http, this.codings); } static Parser<ContentEncoding> parse(Input input, HttpParser http, Parser<FingerTrieSeq<String>> codings) { if (codings == null) { codings = http.parseTokenList(input); } else { codings = codings.feed(input); } if (codings.isDone()) { final FingerTrieSeq<String> tokens = codings.bind(); if (!tokens.isEmpty()) { return done(ContentEncoding.from(tokens)); } else { return error(Diagnostic.expected("content coding", input)); } } else if (codings.isError()) { return codings.asError(); } else if (input.isError()) { return error(input.trap()); } return new ContentEncodingParser(http, codings); } static Parser<ContentEncoding> parse(Input input, HttpParser http) { return parse(input, http, null); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/ContentLength.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Base10; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Writer; import swim.http.HttpHeader; import swim.http.HttpParser; import swim.http.HttpWriter; import swim.util.Murmur3; public final class ContentLength extends HttpHeader { final long length; ContentLength(long length) { this.length = length; } @Override public String lowerCaseName() { return "content-length"; } @Override public String name() { return "Content-Length"; } public long length() { return this.length; } @Override public Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http) { return Base10.writeLong(this.length, output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof ContentLength) { final ContentLength that = (ContentLength) other; return this.length == that.length; } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(ContentLength.class); } return Murmur3.mash(Murmur3.mix(hashSeed, Murmur3.hash(this.length))); } @Override public void debug(Output<?> output) { output = output.write("ContentLength").write('.').write("from").write('(') .debug(this.length).write(')'); } private static int hashSeed; public static ContentLength from(long length) { if (length < 0L) { throw new IllegalArgumentException(Long.toString(length)); } return new ContentLength(length); } public static Parser<ContentLength> parseHttpValue(Input input, HttpParser http) { return ContentLengthParser.parse(input); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/ContentLengthParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Base10; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; final class ContentLengthParser extends Parser<ContentLength> { final long length; final int step; ContentLengthParser(long length, int step) { this.length = length; this.step = step; } ContentLengthParser() { this(0L, 1); } @Override public Parser<ContentLength> feed(Input input) { return parse(input, this.length, this.step); } static Parser<ContentLength> parse(Input input, long length, int step) { int c = 0; if (step == 1) { if (input.isCont()) { c = input.head(); if (Base10.isDigit(c)) { input = input.step(); length = (long) Base10.decodeDigit(c); step = 2; } else { return error(Diagnostic.expected("digit", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("digit", input)); } } if (step == 2) { while (input.isCont()) { c = input.head(); if (Base10.isDigit(c)) { input = input.step(); length = 10L * length + (long) Base10.decodeDigit(c); if (length < 0L) { return error(Diagnostic.message("content length overflow", input)); } } else { break; } } if (!input.isEmpty()) { return done(ContentLength.from(length)); } } if (input.isError()) { return error(input.trap()); } return new ContentLengthParser(length, step); } static Parser<ContentLength> parse(Input input) { return parse(input, 0L, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/ContentType.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Writer; import swim.collections.HashTrieMap; import swim.http.HttpHeader; import swim.http.HttpParser; import swim.http.HttpWriter; import swim.http.MediaType; import swim.util.Murmur3; public final class ContentType extends HttpHeader { final MediaType mediaType; ContentType(MediaType mediaType) { this.mediaType = mediaType; } @Override public String lowerCaseName() { return "content-type"; } @Override public String name() { return "Content-Type"; } public MediaType mediaType() { return this.mediaType; } public String type() { return this.mediaType.type(); } public String subtype() { return this.mediaType.subtype(); } public HashTrieMap<String, String> params() { return this.mediaType.params(); } public String getParam(String key) { return this.mediaType.getParam(key); } public ContentType param(String key, String value) { return from(this.mediaType.param(key, value)); } @Override public Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http) { return this.mediaType.writeHttp(output, http); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof ContentType) { final ContentType that = (ContentType) other; return this.mediaType.equals(that.mediaType); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(ContentType.class); } return Murmur3.mash(Murmur3.mix(hashSeed, this.mediaType.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("ContentType").write('.').write("from").write('(') .debug(this.mediaType.type()).write(", ").write(this.mediaType.subtype()).write(')'); for (HashTrieMap.Entry<String, String> param : this.mediaType.params()) { output = output.write('.').write("param").write('(') .debug(param.getKey()).write(", ").debug(param.getValue()).write(')'); } } private static int hashSeed; public static ContentType from(MediaType mediaType) { return new ContentType(mediaType); } public static ContentType from(String type, String subtype, HashTrieMap<String, String> params) { return from(MediaType.from(type, subtype, params)); } public static ContentType from(String type, String subtype) { return from(MediaType.from(type, subtype)); } public static ContentType from(String mediaType) { return from(MediaType.parse(mediaType)); } public static Parser<ContentType> parseHttpValue(Input input, HttpParser http) { return ContentTypeParser.parse(input, http); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/ContentTypeParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Input; import swim.codec.Parser; import swim.http.HttpParser; import swim.http.MediaType; final class ContentTypeParser extends Parser<ContentType> { final HttpParser http; final Parser<MediaType> mediaType; ContentTypeParser(HttpParser http, Parser<MediaType> mediaType) { this.http = http; this.mediaType = mediaType; } ContentTypeParser(HttpParser http) { this(http, null); } @Override public Parser<ContentType> feed(Input input) { return parse(input, this.http, this.mediaType); } static Parser<ContentType> parse(Input input, HttpParser http, Parser<MediaType> mediaType) { if (mediaType == null) { mediaType = http.parseMediaType(input); } else { mediaType = mediaType.feed(input); } if (mediaType.isDone()) { return done(ContentType.from(mediaType.bind())); } else if (mediaType.isError()) { return mediaType.asError(); } else if (input.isError()) { return error(input.trap()); } return new ContentTypeParser(http, mediaType); } static Parser<ContentType> parse(Input input, HttpParser http) { return parse(input, http, null); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/Expect.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Writer; import swim.http.HttpHeader; import swim.http.HttpParser; import swim.http.HttpWriter; import swim.util.Murmur3; public final class Expect extends HttpHeader { final String value; Expect(String value) { this.value = value; } @Override public boolean isBlank() { return this.value.isEmpty(); } @Override public String lowerCaseName() { return "expect"; } @Override public String name() { return "Expect"; } @Override public String value() { return this.value; } public boolean is100Continue() { return "100-continue".equals(this.value); } @Override public Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http) { return http.writePhrase(this.value, output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof Expect) { final Expect that = (Expect) other; return this.value.equals(that.value); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(Expect.class); } return Murmur3.mash(Murmur3.mix(hashSeed, this.value.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("Expect").write('.').write("from").write('(').debug(this.value).write(')'); } private static int hashSeed; public static Expect from(String value) { return new Expect(value); } public static Parser<Expect> parseHttpValue(Input input, HttpParser http) { return ExpectParser.parse(input); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/ExpectParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Utf8; import swim.http.Http; final class ExpectParser extends Parser<Expect> { final Output<String> value; final int step; ExpectParser(Output<String> value, int step) { this.value = value; this.step = step; } ExpectParser() { this(null, 1); } @Override public Parser<Expect> feed(Input input) { return parse(input, this.value, this.step); } static Parser<Expect> parse(Input input, Output<String> value, int step) { int c = 0; do { if (step == 1) { if (value == null) { value = Utf8.decodedString(); } while (input.isCont()) { c = input.head(); if (Http.isFieldChar(c)) { input = input.step(); value.write(c); } else { break; } } if (input.isCont() && Http.isSpace(c)) { input = input.step(); step = 2; } else if (!input.isEmpty()) { return done(Expect.from(value.bind())); } } if (step == 2) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont() && Http.isFieldChar(c)) { input = input.step(); value.write(' '); value.write(c); step = 1; continue; } else if (!input.isEmpty()) { return done(Expect.from(value.bind())); } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new ExpectParser(value, step); } static Parser<Expect> parse(Input input) { return parse(input, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/Host.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import java.net.InetSocketAddress; import java.net.UnknownHostException; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Writer; import swim.http.HttpHeader; import swim.http.HttpParser; import swim.http.HttpWriter; import swim.uri.UriAuthority; import swim.uri.UriHost; import swim.uri.UriPort; import swim.util.Murmur3; public final class Host extends HttpHeader { final UriHost host; final UriPort port; Host(UriHost host, UriPort port) { this.host = host; this.port = port; } @Override public String lowerCaseName() { return "host"; } @Override public String name() { return "Host"; } public UriHost getHost() { return this.host; } public UriPort port() { return this.port; } public InetSocketAddress inetSocketAddress() throws UnknownHostException { return new InetSocketAddress(host.inetAddress(), port.number()); } @Override public Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http) { return HostWriter.write(output, this.host, this.port); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof Host) { final Host that = (Host) other; return this.host.equals(that.host) && this.port.equals(that.port); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(Host.class); } return Murmur3.mash(Murmur3.mix(Murmur3.mix(hashSeed, this.host.hashCode()), this.port.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("Host").write('.').write("from").write('(').debug(this.host.toString()); if (this.port.isDefined()) { output = output.write(", ").debug(this.port.number()); } output = output.write(')'); } private static int hashSeed; public static Host from(UriHost host, UriPort port) { return new Host(host, port); } public static Host from(UriHost host) { return new Host(host, UriPort.undefined()); } public static Host from(UriAuthority authority) { return new Host(authority.host(), authority.port()); } public static Host from(String host, int port) { return new Host(UriHost.parse(host), UriPort.from(port)); } public static Host from(String host) { return new Host(UriHost.parse(host), UriPort.undefined()); } public static Host from(InetSocketAddress address) { return new Host(UriHost.inetAddress(address.getAddress()), UriPort.from(address.getPort())); } public static Parser<Host> parseHttpValue(Input input, HttpParser http) { return HostParser.parse(input); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/HostParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Input; import swim.codec.Parser; import swim.uri.Uri; import swim.uri.UriHost; import swim.uri.UriPort; final class HostParser extends Parser<Host> { final Parser<UriHost> host; final Parser<UriPort> port; final int step; HostParser(Parser<UriHost> host, Parser<UriPort> port, int step) { this.host = host; this.port = port; this.step = step; } HostParser() { this(null, null, 1); } @Override public Parser<Host> feed(Input input) { return parse(input, this.host, this.port, this.step); } static Parser<Host> parse(Input input, Parser<UriHost> host, Parser<UriPort> port, int step) { if (step == 1) { if (host == null) { host = Uri.standardParser().parseHost(input); } else { host = host.feed(input); } if (host.isDone()) { step = 2; } else if (host.isError()) { return host.asError(); } } if (step == 2) { if (input.isCont() && input.head() == ':') { input = input.step(); step = 3; } else if (!input.isEmpty()) { return done(Host.from(host.bind())); } } if (step == 3) { if (port == null) { port = Uri.standardParser().parsePort(input); } else { port = port.feed(input); } if (port.isDone()) { return done(Host.from(host.bind(), port.bind())); } else if (port.isError()) { return port.asError(); } } if (input.isError()) { return error(input.trap()); } return new HostParser(host, port, step); } static Parser<Host> parse(Input input) { return parse(input, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/HostWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Base10; import swim.codec.Output; import swim.codec.Unicode; import swim.codec.Writer; import swim.codec.WriterException; import swim.uri.UriHost; import swim.uri.UriPort; final class HostWriter extends Writer<Object, Object> { final UriHost host; final UriPort port; final Writer<?, ?> part; final int step; HostWriter(UriHost host, UriPort port, Writer<?, ?> part, int step) { this.host = host; this.port = port; this.part = part; this.step = step; } HostWriter(UriHost host, UriPort port) { this(host, port, null, 1); } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.host, this.port, this.part, this.step); } static Writer<Object, Object> write(Output<?> output, UriHost host, UriPort port, Writer<?, ?> part, int step) { if (step == 1) { if (part == null) { part = Unicode.writeString(host.toString(), output); } else { part = part.pull(output); } if (part.isDone()) { part = null; if (!port.isDefined()) { return done(); } else { step = 2; } } else if (part.isError()) { return part.asError(); } } if (step == 2 && output.isCont()) { output = output.write(':'); step = 3; } if (step == 3) { if (part == null) { part = Base10.writeInt(port.number(), output); } else { part = part.pull(output); } if (part.isDone()) { return done(); } else if (part.isError()) { return part.asError(); } } if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new HostWriter(host, port, part, step); } static Writer<Object, Object> write(Output<?> output, UriHost host, UriPort port) { return write(output, host, port, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/MaxForwards.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Base10; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Writer; import swim.http.HttpHeader; import swim.http.HttpParser; import swim.http.HttpWriter; import swim.util.Murmur3; public final class MaxForwards extends HttpHeader { final int count; MaxForwards(int count) { this.count = count; } @Override public String lowerCaseName() { return "max-forwards"; } @Override public String name() { return "Max-Forwards"; } public int count() { return this.count; } @Override public Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http) { return Base10.writeInt(this.count, output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof MaxForwards) { final MaxForwards that = (MaxForwards) other; return this.count == that.count; } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(MaxForwards.class); } return Murmur3.mash(Murmur3.mix(hashSeed, this.count)); } @Override public void debug(Output<?> output) { output = output.write("MaxForwards").write('.').write("from").write('(') .debug(this.count).write(')'); } private static int hashSeed; public static MaxForwards from(int count) { if (count < 0) { throw new IllegalArgumentException(Integer.toString(count)); } return new MaxForwards(count); } public static Parser<MaxForwards> parseHttpValue(Input input, HttpParser http) { return MaxForwardsParser.parse(input); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/MaxForwardsParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Base10; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; final class MaxForwardsParser extends Parser<MaxForwards> { final int count; final int step; MaxForwardsParser(int count, int step) { this.count = count; this.step = step; } MaxForwardsParser() { this(0, 1); } @Override public Parser<MaxForwards> feed(Input input) { return parse(input, this.count, this.step); } static Parser<MaxForwards> parse(Input input, int count, int step) { int c = 0; if (step == 1) { if (input.isCont()) { c = input.head(); if (Base10.isDigit(c)) { input = input.step(); count = Base10.decodeDigit(c); step = 2; } else { return error(Diagnostic.expected("digit", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("digit", input)); } } if (step == 2) { while (input.isCont()) { c = input.head(); if (Base10.isDigit(c)) { input = input.step(); count = 10 * count + Base10.decodeDigit(c); if (count < 0) { return error(Diagnostic.message("max forwards overflow", input)); } } else { break; } } if (!input.isEmpty()) { return done(MaxForwards.from(count)); } } if (input.isError()) { return error(input.trap()); } return new MaxForwardsParser(count, step); } static Parser<MaxForwards> parse(Input input) { return parse(input, 0, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/Origin.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Unicode; import swim.codec.Writer; import swim.collections.FingerTrieSeq; import swim.http.HttpHeader; import swim.http.HttpParser; import swim.http.HttpWriter; import swim.uri.Uri; import swim.util.Builder; import swim.util.Murmur3; public final class Origin extends HttpHeader { final FingerTrieSeq<Uri> origins; Origin(FingerTrieSeq<Uri> origins) { this.origins = origins; } @Override public String lowerCaseName() { return "origin"; } @Override public String name() { return "Origin"; } public FingerTrieSeq<Uri> origins() { return this.origins; } @Override public Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http) { if (this.origins.isEmpty()) { return Unicode.writeString("null", output); } else { return OriginWriter.write(output, this.origins.iterator()); } } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof Origin) { final Origin that = (Origin) other; return this.origins.equals(that.origins); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(Origin.class); } return Murmur3.mash(Murmur3.mix(hashSeed, this.origins.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("Origin").write('.'); final int n = this.origins.size(); if (n > 0) { output = output.write("from").write('(').debug(this.origins.head().toString()); for (int i = 1; i < n; i += 1) { output = output.write(", ").write(this.origins.get(i).toString()); } output = output.write(')'); } else { output = output.write("empty").write('(').write(')'); } } private static int hashSeed; private static Origin empty; public static Origin empty() { if (empty == null) { empty = new Origin(FingerTrieSeq.<Uri>empty()); } return empty; } public static Origin from(FingerTrieSeq<Uri> origins) { if (origins.isEmpty()) { return empty(); } else { return new Origin(origins); } } public static Origin from(Uri... origins) { if (origins.length == 0) { return empty(); } else { return new Origin(FingerTrieSeq.of(origins)); } } public static Origin from(String... originStrings) { final Builder<Uri, FingerTrieSeq<Uri>> origins = FingerTrieSeq.builder(); for (int i = 0, n = originStrings.length; i < n; i += 1) { origins.add(Uri.parse(originStrings[i])); } return new Origin(origins.bind()); } public static Parser<Origin> parseHttpValue(Input input, HttpParser http) { return OriginParser.parse(input); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/OriginParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.collections.FingerTrieSeq; import swim.uri.Uri; import swim.uri.UriAuthority; import swim.uri.UriHost; import swim.uri.UriPort; import swim.uri.UriScheme; import swim.util.Builder; final class OriginParser extends Parser<Origin> { final Parser<UriScheme> scheme; final Parser<UriHost> host; final Parser<UriPort> port; final Builder<Uri, FingerTrieSeq<Uri>> origins; final int step; OriginParser(Parser<UriScheme> scheme, Parser<UriHost> host, Parser<UriPort> port, Builder<Uri, FingerTrieSeq<Uri>> origins, int step) { this.scheme = scheme; this.host = host; this.port = port; this.origins = origins; this.step = step; } OriginParser() { this(null, null, null, null, 1); } @Override public Parser<Origin> feed(Input input) { return parse(input, this.scheme, this.host, this.port, this.origins, this.step); } static Parser<Origin> parse(Input input, Parser<UriScheme> scheme, Parser<UriHost> host, Parser<UriPort> port, Builder<Uri, FingerTrieSeq<Uri>> origins, int step) { do { if (step == 1) { if (scheme == null) { scheme = Uri.standardParser().parseScheme(input); } else { scheme = scheme.feed(input); } if (scheme.isDone()) { if (input.isCont() && input.head() == ':') { input = input.step(); step = 2; } else if (!input.isEmpty()) { if (origins == null && "null".equals(scheme.bind().name())) { return done(Origin.empty()); } else { return error(Diagnostic.expected(':', input)); } } } else if (scheme.isError()) { return scheme.asError(); } } if (step == 2) { if (input.isCont() && input.head() == '/') { input = input.step(); step = 3; } else if (!input.isEmpty()) { return error(Diagnostic.expected('/', input)); } } if (step == 3) { if (input.isCont() && input.head() == '/') { input = input.step(); step = 4; } else if (!input.isEmpty()) { return error(Diagnostic.expected('/', input)); } } if (step == 4) { if (host == null) { host = Uri.standardParser().parseHost(input); } else { host = host.feed(input); } if (host.isDone()) { if (input.isCont() && input.head() == ':') { input = input.step(); step = 5; } else if (!input.isEmpty()) { if (origins == null) { origins = FingerTrieSeq.builder(); } origins.add(Uri.from(scheme.bind(), UriAuthority.from(host.bind()))); scheme = null; host = null; step = 6; } } else if (host.isError()) { return host.asError(); } } if (step == 5) { if (port == null) { port = Uri.standardParser().parsePort(input); } else { port = port.feed(input); } if (port.isDone()) { if (origins == null) { origins = FingerTrieSeq.builder(); } origins.add(Uri.from(scheme.bind(), UriAuthority.from(host.bind(), port.bind()))); scheme = null; host = null; port = null; step = 6; } else if (port.isError()) { return port.asError(); } } if (step == 6) { if (input.isCont() && input.head() == ' ') { input = input.step(); step = 1; continue; } else if (!input.isEmpty()) { return done(Origin.from(origins.bind())); } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new OriginParser(scheme, host, port, origins, step); } static Parser<Origin> parse(Input input) { return parse(input, null, null, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/OriginWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import java.util.Iterator; import swim.codec.Base10; import swim.codec.Output; import swim.codec.Unicode; import swim.codec.Writer; import swim.codec.WriterException; import swim.uri.Uri; final class OriginWriter extends Writer<Object, Object> { final Iterator<Uri> origins; final Uri origin; final Writer<?, ?> part; final int step; OriginWriter(Iterator<Uri> origins, Uri origin, Writer<?, ?> part, int step) { this.origins = origins; this.origin = origin; this.part = part; this.step = step; } OriginWriter(Iterator<Uri> origins) { this(origins, null, null, 1); } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.origins, this.origin, this.part, this.step); } static Writer<Object, Object> write(Output<?> output, Iterator<Uri> origins, Uri origin, Writer<?, ?> part, int step) { do { if (step == 1) { if (part == null) { if (!origins.hasNext()) { return done(); } else { origin = origins.next(); part = Unicode.writeString(origin.scheme().toString(), output); } } else { part = part.pull(output); } if (part.isDone()) { part = null; step = 2; } else if (part.isError()) { return part.asError(); } } if (step == 2 && output.isCont()) { output = output.write(':'); step = 3; } if (step == 3 && output.isCont()) { output = output.write('/'); step = 4; } if (step == 4 && output.isCont()) { output = output.write('/'); step = 5; } if (step == 5) { if (part == null) { part = Unicode.writeString(origin.host().toString(), output); } else { part = part.pull(output); } if (part.isDone()) { part = null; if (origin.port().isDefined()) { step = 6; } else if (origins.hasNext()) { origin = null; step = 8; } else { return done(); } } else if (part.isError()) { return part.asError(); } } if (step == 6 && output.isCont()) { output = output.write(':'); step = 7; } if (step == 7) { if (part == null) { part = Base10.writeInt(origin.portNumber(), output); } else { part = part.pull(output); } if (part.isDone()) { part = null; if (origins.hasNext()) { origin = null; step = 8; } else { return done(); } } else if (part.isError()) { return part.asError(); } } if (step == 8 && output.isCont()) { output = output.write(' '); step = 1; continue; } break; } while (true); if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new OriginWriter(origins, origin, part, step); } public static Writer<Object, Object> write(Output<?> output, Iterator<Uri> origins) { return write(output, origins, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/RawHeader.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Writer; import swim.http.HttpHeader; import swim.http.HttpParser; import swim.http.HttpWriter; import swim.util.Murmur3; public final class RawHeader extends HttpHeader { final String lowerCaseName; final String name; final String value; RawHeader(String lowerCaseName, String name, String value) { this.lowerCaseName = lowerCaseName; this.name = name; this.value = value; } @Override public boolean isBlank() { return this.value.isEmpty(); } @Override public String lowerCaseName() { return this.lowerCaseName; } @Override public String name() { return this.name; } @Override public String value() { return this.value; } @Override public Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http) { return http.writeField(this.value, output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof RawHeader) { final RawHeader that = (RawHeader) other; return this.name.equals(that.name) && this.value.equals(that.value); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(RawHeader.class); } return Murmur3.mash(Murmur3.mix(Murmur3.mix(hashSeed, this.name.hashCode()), this.value.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("RawHeader").write('.').write("from").write('(') .debug(this.name).write(", ").debug(this.value).write(')'); } private static int hashSeed; public static RawHeader from(String lowerCaseName, String name, String value) { return new RawHeader(lowerCaseName, name, value); } public static RawHeader from(String name, String value) { return new RawHeader(name.toLowerCase(), name, value); } public static Parser<RawHeader> parseHttpValue(Input input, HttpParser http, String lowerCaseName, String name) { return RawHeaderParser.parse(input, lowerCaseName, name); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/RawHeaderParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Utf8; import swim.http.Http; final class RawHeaderParser extends Parser<RawHeader> { final String lowerCaseName; final String name; final Output<String> value; final int step; RawHeaderParser(String lowerCaseName, String name, Output<String> value, int step) { this.lowerCaseName = lowerCaseName; this.name = name; this.value = value; this.step = step; } RawHeaderParser(String lowerCaseName, String name) { this(lowerCaseName, name, null, 1); } @Override public Parser<RawHeader> feed(Input input) { return parse(input, this.lowerCaseName, this.name, this.value, this.step); } static Parser<RawHeader> parse(Input input, String lowerCaseName, String name, Output<String> value, int step) { int c = 0; do { if (step == 1) { if (value == null) { value = Utf8.decodedString(); } while (input.isCont()) { c = input.head(); if (Http.isFieldChar(c)) { input = input.step(); value.write(c); } else { break; } } if (input.isCont() && Http.isSpace(c)) { input = input.step(); step = 2; } else if (!input.isEmpty()) { return done(RawHeader.from(lowerCaseName, name, value.bind())); } } if (step == 2) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont() && Http.isFieldChar(c)) { input = input.step(); value.write(' '); value.write(c); step = 1; continue; } else if (!input.isEmpty()) { return done(RawHeader.from(lowerCaseName, name, value.bind())); } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new RawHeaderParser(lowerCaseName, name, value, step); } static Parser<RawHeader> parse(Input input, String lowerCaseName, String name) { return parse(input, lowerCaseName, name, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/SecWebSocketAccept.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import java.util.Arrays; import swim.codec.Base64; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Unicode; import swim.codec.Writer; import swim.http.HttpHeader; import swim.http.HttpParser; import swim.http.HttpWriter; import swim.util.Murmur3; public final class SecWebSocketAccept extends HttpHeader { final byte[] digest; SecWebSocketAccept(byte[] digest) { this.digest = digest; } @Override public String lowerCaseName() { return "sec-websocket-accept"; } @Override public String name() { return "Sec-WebSocket-Accept"; } public byte[] digest() { return this.digest; } @Override public Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http) { return Base64.standard().writeByteArray(this.digest, output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof SecWebSocketAccept) { final SecWebSocketAccept that = (SecWebSocketAccept) other; return Arrays.equals(this.digest, that.digest); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(SecWebSocketAccept.class); } return Murmur3.mash(Murmur3.mix(hashSeed, Arrays.hashCode(this.digest))); } @Override public void debug(Output<?> output) { output = output.write("SecWebSocketAccept").write('.').write("from").write('(').write('"'); Base64.standard().writeByteArray(this.digest, output); output = output.write('"').write(')'); } private static int hashSeed; public static SecWebSocketAccept from(byte[] digest) { return new SecWebSocketAccept(digest); } public static SecWebSocketAccept from(String digestString) { final Input input = Unicode.stringInput(digestString); Parser<byte[]> parser = Base64.standard().parseByteArray(input); if (input.isCont() && !parser.isError()) { parser = Parser.error(Diagnostic.unexpected(input)); } return new SecWebSocketAccept(parser.bind()); } public static Parser<SecWebSocketAccept> parseHttpValue(Input input, HttpParser http) { return SecWebSocketAcceptParser.parse(input); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/SecWebSocketAcceptParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Base64; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; final class SecWebSocketAcceptParser extends Parser<SecWebSocketAccept> { final Parser<byte[]> digest; SecWebSocketAcceptParser(Parser<byte[]> digest) { this.digest = digest; } SecWebSocketAcceptParser() { this(null); } @Override public Parser<SecWebSocketAccept> feed(Input input) { return parse(input, this.digest); } static Parser<SecWebSocketAccept> parse(Input input, Parser<byte[]> digest) { if (digest == null) { digest = Base64.standard().parseByteArray(input); } else { digest = digest.feed(input); } if (digest.isDone()) { final byte[] data = digest.bind(); if (data.length != 0) { return done(SecWebSocketAccept.from(data)); } else { return error(Diagnostic.expected("base64 digest", input)); } } else if (digest.isError()) { return digest.asError(); } else if (input.isError()) { return error(input.trap()); } return new SecWebSocketAcceptParser(digest); } static Parser<SecWebSocketAccept> parse(Input input) { return parse(input, null); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/SecWebSocketExtensions.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Writer; import swim.collections.FingerTrieSeq; import swim.http.HttpHeader; import swim.http.HttpParser; import swim.http.HttpWriter; import swim.http.WebSocketExtension; import swim.util.Builder; import swim.util.Murmur3; public final class SecWebSocketExtensions extends HttpHeader { final FingerTrieSeq<WebSocketExtension> extensions; SecWebSocketExtensions(FingerTrieSeq<WebSocketExtension> extensions) { this.extensions = extensions; } @Override public boolean isBlank() { return this.extensions.isEmpty(); } @Override public String lowerCaseName() { return "sec-websocket-extensions"; } @Override public String name() { return "Sec-WebSocket-Extensions"; } public FingerTrieSeq<WebSocketExtension> extensions() { return this.extensions; } @Override public Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http) { return http.writeParamList(this.extensions.iterator(), output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof SecWebSocketExtensions) { final SecWebSocketExtensions that = (SecWebSocketExtensions) other; return this.extensions.equals(that.extensions); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(SecWebSocketExtensions.class); } return Murmur3.mash(Murmur3.mix(hashSeed, this.extensions.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("SecWebSocketExtensions").write('.').write("from").write('('); final int n = this.extensions.size(); if (n > 0) { output.debug(this.extensions.head()); for (int i = 1; i < n; i += 1) { output = output.write(", ").debug(this.extensions.get(i)); } } output = output.write(')'); } private static int hashSeed; public static SecWebSocketExtensions from(FingerTrieSeq<WebSocketExtension> extensions) { return new SecWebSocketExtensions(extensions); } public static SecWebSocketExtensions from(WebSocketExtension... extensions) { return new SecWebSocketExtensions(FingerTrieSeq.of(extensions)); } public static SecWebSocketExtensions from(String... extensionStrings) { final Builder<WebSocketExtension, FingerTrieSeq<WebSocketExtension>> extensions = FingerTrieSeq.builder(); for (int i = 0, n = extensionStrings.length; i < n; i += 1) { extensions.add(WebSocketExtension.parse(extensionStrings[i])); } return new SecWebSocketExtensions(extensions.bind()); } public static Parser<SecWebSocketExtensions> parseHttpValue(Input input, HttpParser http) { return SecWebSocketExtensionsParser.parse(input, http); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/SecWebSocketExtensionsParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.collections.FingerTrieSeq; import swim.http.Http; import swim.http.HttpParser; import swim.http.WebSocketExtension; import swim.util.Builder; final class SecWebSocketExtensionsParser extends Parser<SecWebSocketExtensions> { final HttpParser http; final Parser<WebSocketExtension> extension; final Builder<WebSocketExtension, FingerTrieSeq<WebSocketExtension>> extensions; final int step; SecWebSocketExtensionsParser(HttpParser http, Parser<WebSocketExtension> extension, Builder<WebSocketExtension, FingerTrieSeq<WebSocketExtension>> extensions, int step) { this.http = http; this.extension = extension; this.extensions = extensions; this.step = step; } SecWebSocketExtensionsParser(HttpParser http) { this(http, null, null, 1); } @Override public Parser<SecWebSocketExtensions> feed(Input input) { return parse(input, this.http, this.extension, this.extensions, this.step); } static Parser<SecWebSocketExtensions> parse(Input input, HttpParser http, Parser<WebSocketExtension> extension, Builder<WebSocketExtension, FingerTrieSeq<WebSocketExtension>> extensions, int step) { int c = 0; if (step == 1) { if (extension == null) { extension = http.parseWebSocketExtension(input); } else { extension = extension.feed(input); } if (extension.isDone()) { if (extensions == null) { extensions = FingerTrieSeq.builder(); } extensions.add(extension.bind()); extension = null; step = 2; } else if (extension.isError()) { return extension.asError(); } } do { if (step == 2) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont() && c == ',') { input = input.step(); step = 3; } else if (!input.isEmpty()) { return done(SecWebSocketExtensions.from(extensions.bind())); } } if (step == 3) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { step = 4; } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } if (step == 4) { if (extension == null) { extension = http.parseWebSocketExtension(input); } else { extension = extension.feed(input); } if (extension.isDone()) { extensions.add(extension.bind()); extension = null; step = 2; continue; } else if (extension.isError()) { return extension.asError(); } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new SecWebSocketExtensionsParser(http, extension, extensions, step); } static Parser<SecWebSocketExtensions> parse(Input input, HttpParser http) { return parse(input, http, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/SecWebSocketKey.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Arrays; import java.util.concurrent.ThreadLocalRandom; import swim.codec.Base64; import swim.codec.Binary; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Unicode; import swim.codec.Writer; import swim.http.HttpException; import swim.http.HttpHeader; import swim.http.HttpParser; import swim.http.HttpWriter; import swim.util.Murmur3; public final class SecWebSocketKey extends HttpHeader { final byte[] key; SecWebSocketKey(byte[] key) { this.key = key; } @Override public String lowerCaseName() { return "sec-websocket-key"; } @Override public String name() { return "Sec-WebSocket-Key"; } public byte[] key() { return this.key; } public SecWebSocketAccept accept() { Output<byte[]> output = Binary.byteArrayOutput(60); Base64.standard().writeByteArray(this.key, output); final String seed = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; for (int i = 0, n = seed.length(); i < n; i += 1) { output = output.write((byte) seed.charAt(i)); } try { final byte[] digest = MessageDigest.getInstance("SHA-1").digest(output.bind()); return new SecWebSocketAccept(digest); } catch (NoSuchAlgorithmException cause) { throw new HttpException(cause); } } @Override public Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http) { return Base64.standard().writeByteArray(this.key, output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof SecWebSocketKey) { final SecWebSocketKey that = (SecWebSocketKey) other; return Arrays.equals(this.key, that.key); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(SecWebSocketKey.class); } return Murmur3.mash(Murmur3.mix(hashSeed, Arrays.hashCode(this.key))); } @Override public void debug(Output<?> output) { output = output.write("SecWebSocketKey").write('.').write("from").write('(').write('"'); Base64.standard().writeByteArray(this.key, output); output = output.write('"').write(')'); } private static int hashSeed; public static SecWebSocketKey from(byte[] key) { return new SecWebSocketKey(key); } public static SecWebSocketKey from(String keyString) { final Input input = Unicode.stringInput(keyString); Parser<byte[]> parser = Base64.standard().parseByteArray(input); if (input.isCont() && !parser.isError()) { parser = Parser.error(Diagnostic.unexpected(input)); } return new SecWebSocketKey(parser.bind()); } public static SecWebSocketKey generate() { final byte[] key = new byte[16]; ThreadLocalRandom.current().nextBytes(key); return new SecWebSocketKey(key); } public static Parser<SecWebSocketKey> parseHttpValue(Input input, HttpParser http) { return SecWebSocketKeyParser.parse(input); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/SecWebSocketKeyParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Base64; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; final class SecWebSocketKeyParser extends Parser<SecWebSocketKey> { final Parser<byte[]> key; SecWebSocketKeyParser(Parser<byte[]> key) { this.key = key; } SecWebSocketKeyParser() { this(null); } @Override public Parser<SecWebSocketKey> feed(Input input) { return parse(input, key); } static Parser<SecWebSocketKey> parse(Input input, Parser<byte[]> key) { if (key == null) { key = Base64.standard().parseByteArray(input); } else { key = key.feed(input); } if (key.isDone()) { final byte[] data = key.bind(); if (data.length != 0) { return done(SecWebSocketKey.from(data)); } else { return error(Diagnostic.expected("base64 digest", input)); } } else if (key.isError()) { return key.asError(); } else if (input.isError()) { return error(input.trap()); } return new SecWebSocketKeyParser(key); } static Parser<SecWebSocketKey> parse(Input input) { return parse(input, null); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/SecWebSocketProtocol.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Writer; import swim.collections.FingerTrieSeq; import swim.http.HttpHeader; import swim.http.HttpParser; import swim.http.HttpWriter; import swim.util.Murmur3; public final class SecWebSocketProtocol extends HttpHeader { final FingerTrieSeq<String> protocols; SecWebSocketProtocol(FingerTrieSeq<String> protocols) { this.protocols = protocols; } @Override public boolean isBlank() { return this.protocols.isEmpty(); } @Override public String lowerCaseName() { return "sec-websocket-protocol"; } @Override public String name() { return "Sec-WebSocket-Protocol"; } public FingerTrieSeq<String> protocols() { return this.protocols; } @Override public Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http) { return http.writeTokenList(this.protocols.iterator(), output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof SecWebSocketProtocol) { final SecWebSocketProtocol that = (SecWebSocketProtocol) other; return this.protocols.equals(that.protocols); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(SecWebSocketProtocol.class); } return Murmur3.mash(Murmur3.mix(hashSeed, this.protocols.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("SecWebSocketProtocol").write('.').write("from").write('('); final int n = this.protocols.size(); if (n > 0) { output.debug(this.protocols.head()); for (int i = 1; i < n; i += 1) { output = output.write(", ").debug(this.protocols.head()); } } output = output.write(')'); } private static int hashSeed; public static SecWebSocketProtocol from(FingerTrieSeq<String> protocols) { return new SecWebSocketProtocol(protocols); } public static SecWebSocketProtocol from(String... protocols) { return new SecWebSocketProtocol(FingerTrieSeq.of(protocols)); } public static Parser<SecWebSocketProtocol> parseHttpValue(Input input, HttpParser http) { return SecWebSocketProtocolParser.parse(input, http); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/SecWebSocketProtocolParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.collections.FingerTrieSeq; import swim.http.HttpParser; final class SecWebSocketProtocolParser extends Parser<SecWebSocketProtocol> { final HttpParser http; final Parser<FingerTrieSeq<String>> protocols; SecWebSocketProtocolParser(HttpParser http, Parser<FingerTrieSeq<String>> protocols) { this.http = http; this.protocols = protocols; } SecWebSocketProtocolParser(HttpParser http) { this(http, null); } @Override public Parser<SecWebSocketProtocol> feed(Input input) { return parse(input, this.http, this.protocols); } static Parser<SecWebSocketProtocol> parse(Input input, HttpParser http, Parser<FingerTrieSeq<String>> protocols) { if (protocols == null) { protocols = http.parseTokenList(input); } else { protocols = protocols.feed(input); } if (protocols.isDone()) { final FingerTrieSeq<String> tokens = protocols.bind(); if (!tokens.isEmpty()) { return done(SecWebSocketProtocol.from(tokens)); } else { return error(Diagnostic.expected("websocket protocol", input)); } } else if (protocols.isError()) { return protocols.asError(); } else if (input.isError()) { return error(input.trap()); } return new SecWebSocketProtocolParser(http, protocols); } static Parser<SecWebSocketProtocol> parse(Input input, HttpParser http) { return parse(input, http, null); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/SecWebSocketVersion.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Writer; import swim.collections.FingerTrieSeq; import swim.http.HttpHeader; import swim.http.HttpParser; import swim.http.HttpWriter; import swim.util.Murmur3; public final class SecWebSocketVersion extends HttpHeader { final FingerTrieSeq<Integer> versions; SecWebSocketVersion(FingerTrieSeq<Integer> versions) { this.versions = versions; } @Override public boolean isBlank() { return this.versions.isEmpty(); } @Override public String lowerCaseName() { return "sec-websocket-version"; } @Override public String name() { return "Sec-WebSocket-Version"; } public FingerTrieSeq<Integer> versions() { return this.versions; } public boolean supports(int version) { return this.versions.contains(version); } @Override public Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http) { return http.writeTokenList(this.versions.iterator(), output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof SecWebSocketVersion) { final SecWebSocketVersion that = (SecWebSocketVersion) other; return this.versions.equals(that.versions); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(SecWebSocketVersion.class); } return Murmur3.mash(Murmur3.mix(hashSeed, this.versions.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("SecWebSocketVersion").write('.').write("from").write('('); final int n = this.versions.size(); if (n > 0) { output.debug(this.versions.head()); for (int i = 1; i < n; i += 1) { output = output.write(", ").debug(this.versions.get(i)); } } output = output.write(')'); } private static int hashSeed; private static SecWebSocketVersion version13; public static SecWebSocketVersion version13() { if (version13 == null) { version13 = new SecWebSocketVersion(FingerTrieSeq.of(13)); } return version13; } public static SecWebSocketVersion from(FingerTrieSeq<Integer> versions) { if (versions.size() == 1) { final int version = versions.head(); if (version == 13) { return version13(); } } return new SecWebSocketVersion(versions); } public static SecWebSocketVersion from(Integer... versions) { if (versions.length == 1) { final int version = versions[0]; if (version == 13) { return version13(); } } return new SecWebSocketVersion(FingerTrieSeq.of(versions)); } public static Parser<SecWebSocketVersion> parseHttpValue(Input input, HttpParser http) { return SecWebSocketVersionParser.parse(input); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/SecWebSocketVersionParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Base10; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.collections.FingerTrieSeq; import swim.http.Http; import swim.util.Builder; final class SecWebSocketVersionParser extends Parser<SecWebSocketVersion> { final int version; final Builder<Integer, FingerTrieSeq<Integer>> versions; final int step; SecWebSocketVersionParser(int version, Builder<Integer, FingerTrieSeq<Integer>> versions, int step) { this.version = version; this.versions = versions; this.step = step; } SecWebSocketVersionParser() { this(0, null, 1); } @Override public Parser<SecWebSocketVersion> feed(Input input) { return parse(input, this.version, this.versions, this.step); } static Parser<SecWebSocketVersion> parse(Input input, int version, Builder<Integer, FingerTrieSeq<Integer>> versions, int step) { int c = 0; if (step == 1) { if (input.isCont()) { c = input.head(); if (c == '0') { input = input.step(); if (versions == null) { versions = FingerTrieSeq.builder(); } versions.add(0); version = 0; step = 3; } else if (c >= '1' && c <= '9') { input = input.step(); version = Base10.decodeDigit(c); step = 2; } else { return error(Diagnostic.expected("websocket version", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("websocket version", input)); } } if (step == 2) { while (input.isCont()) { c = input.head(); if (Base10.isDigit(c)) { input = input.step(); version = 10 * version + Base10.decodeDigit(c); if (version < 0) { return error(Diagnostic.message("websocket version overflow", input)); } } else { break; } } if (!input.isEmpty()) { if (versions == null) { versions = FingerTrieSeq.builder(); } versions.add(version); version = 0; step = 3; } } do { if (step == 3) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont() && c == ',') { input = input.step(); step = 4; } else if (!input.isEmpty()) { return done(SecWebSocketVersion.from(versions.bind())); } } if (step == 4) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { step = 5; } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } if (step == 5) { if (input.isCont()) { c = input.head(); if (c == '0') { input = input.step(); versions.add(0); version = 0; step = 3; continue; } else if (c >= '1' && c <= '9') { input = input.step(); version = Base10.decodeDigit(c); step = 6; } else { return error(Diagnostic.expected("websocket version", input)); } } else if (input.isDone()) { return error(Diagnostic.expected("websocket version", input)); } } if (step == 6) { while (input.isCont()) { c = input.head(); if (Base10.isDigit(c)) { input = input.step(); version = 10 * version + Base10.decodeDigit(c); if (version < 0) { return error(Diagnostic.message("websocket version overflow", input)); } } else { break; } } if (!input.isEmpty()) { versions.add(version); version = 0; step = 3; continue; } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new SecWebSocketVersionParser(version, versions, step); } static Parser<SecWebSocketVersion> parse(Input input) { return parse(input, 0, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/Server.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Writer; import swim.collections.FingerTrieSeq; import swim.http.HttpHeader; import swim.http.HttpParser; import swim.http.HttpWriter; import swim.http.Product; import swim.util.Builder; import swim.util.Murmur3; public final class Server extends HttpHeader { final FingerTrieSeq<Product> products; Server(FingerTrieSeq<Product> products) { this.products = products; } @Override public String lowerCaseName() { return "server"; } @Override public String name() { return "Server"; } public FingerTrieSeq<Product> products() { return this.products; } @Override public Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http) { return ServerWriter.write(output, http, this.products.iterator()); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof Server) { final Server that = (Server) other; return this.products.equals(that.products); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(Server.class); } return Murmur3.mash(Murmur3.mix(hashSeed, this.products.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("Server").write('.').write("from").write('('); final int n = this.products.size(); if (n > 0) { output.debug(this.products.head()); for (int i = 1; i < n; i += 1) { output = output.write(", ").debug(this.products.get(i)); } } output = output.write(')'); } private static int hashSeed; public static Server from(FingerTrieSeq<Product> products) { return new Server(products); } public static Server from(Product... products) { return new Server(FingerTrieSeq.of(products)); } public static Server from(String... productStrings) { final Builder<Product, FingerTrieSeq<Product>> products = FingerTrieSeq.builder(); for (int i = 0, n = productStrings.length; i < n; i += 1) { products.add(Product.parse(productStrings[i])); } return new Server(products.bind()); } public static Parser<Server> parseHttpValue(Input input, HttpParser http) { return ServerParser.parse(input, http); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/ServerParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Input; import swim.codec.Parser; import swim.collections.FingerTrieSeq; import swim.http.Http; import swim.http.HttpParser; import swim.http.Product; import swim.util.Builder; final class ServerParser extends Parser<Server> { final HttpParser http; final Parser<Product> product; final Builder<Product, FingerTrieSeq<Product>> products; final int step; ServerParser(HttpParser http, Parser<Product> product, Builder<Product, FingerTrieSeq<Product>> products, int step) { this.http = http; this.product = product; this.products = products; this.step = step; } ServerParser(HttpParser http) { this(http, null, null, 1); } @Override public Parser<Server> feed(Input input) { return parse(input, this.http, this.product, this.products, this.step); } static Parser<Server> parse(Input input, HttpParser http, Parser<Product> product, Builder<Product, FingerTrieSeq<Product>> products, int step) { int c = 0; if (step == 1) { if (product == null) { product = http.parseProduct(input); } else { product = product.feed(input); } if (product.isDone()) { if (products == null) { products = FingerTrieSeq.builder(); } products.add(product.bind()); product = null; step = 2; } else if (product.isError()) { return product.asError(); } } do { if (step == 2) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont() && Http.isTokenChar(c)) { step = 3; } else if (!input.isEmpty()) { return done(Server.from(products.bind())); } } if (step == 3) { if (product == null) { product = http.parseProduct(input); } else { product = product.feed(input); } if (product.isDone()) { products.add(product.bind()); product = null; step = 2; continue; } else if (product.isError()) { return product.asError(); } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new ServerParser(http, product, products, step); } static Parser<Server> parse(Input input, HttpParser http) { return parse(input, http, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/ServerWriter.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import java.util.Iterator; import swim.codec.Output; import swim.codec.Writer; import swim.codec.WriterException; import swim.http.HttpWriter; import swim.http.Product; final class ServerWriter extends Writer<Object, Object> { final HttpWriter http; final Iterator<Product> products; final Writer<?, ?> part; final int step; ServerWriter(HttpWriter http, Iterator<Product> products, Writer<?, ?> part, int step) { this.http = http; this.products = products; this.part = part; this.step = step; } @Override public Writer<Object, Object> pull(Output<?> output) { return write(output, this.http, this.products, this.part, this.step); } static Writer<Object, Object> write(Output<?> output, HttpWriter http, Iterator<Product> products, Writer<?, ?> part, int step) { do { if (step == 1) { if (part == null) { if (!products.hasNext()) { return done(); } else { part = products.next().writeHttp(output, http); } } else { part = part.pull(output); } if (part.isDone()) { part = null; if (!products.hasNext()) { return done(); } else { step = 2; } } else if (part.isError()) { return part.asError(); } } if (step == 2 && output.isCont()) { output = output.write(' '); step = 1; continue; } break; } while (true); if (output.isDone()) { return error(new WriterException("truncated")); } else if (output.isError()) { return error(output.trap()); } return new ServerWriter(http, products, part, step); } static Writer<Object, Object> write(Output<?> output, HttpWriter http, Iterator<Product> products) { return write(output, http, products, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/TransferEncoding.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Writer; import swim.collections.FingerTrieSeq; import swim.http.HttpHeader; import swim.http.HttpParser; import swim.http.HttpWriter; import swim.http.TransferCoding; import swim.util.Builder; import swim.util.Murmur3; public final class TransferEncoding extends HttpHeader { final FingerTrieSeq<TransferCoding> codings; TransferEncoding(FingerTrieSeq<TransferCoding> codings) { this.codings = codings; } @Override public boolean isBlank() { return this.codings.isEmpty(); } @Override public String lowerCaseName() { return "transfer-encoding"; } @Override public String name() { return "Transfer-Encoding"; } public FingerTrieSeq<TransferCoding> codings() { return this.codings; } @Override public Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http) { return http.writeParamList(this.codings.iterator(), output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof TransferEncoding) { final TransferEncoding that = (TransferEncoding) other; return this.codings.equals(that.codings); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(TransferEncoding.class); } return Murmur3.mash(Murmur3.mix(hashSeed, this.codings.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("TransferEncoding").write('.').write("from").write('('); final int n = this.codings.size(); if (n != 0) { output.debug(this.codings.head()); for (int i = 1; i < n; i += 1) { output = output.write(", ").debug(this.codings.get(i)); } } output = output.write(')'); } private static int hashSeed; private static TransferEncoding chunked; public static TransferEncoding chunked() { if (chunked == null) { chunked = new TransferEncoding(FingerTrieSeq.of(TransferCoding.chunked())); } return chunked; } public static TransferEncoding from(FingerTrieSeq<TransferCoding> codings) { return new TransferEncoding(codings); } public static TransferEncoding from(TransferCoding... codings) { return from(FingerTrieSeq.of(codings)); } public static TransferEncoding from(String... codingStrings) { final Builder<TransferCoding, FingerTrieSeq<TransferCoding>> codings = FingerTrieSeq.builder(); for (int i = 0, n = codingStrings.length; i < n; i += 1) { codings.add(TransferCoding.parse(codingStrings[i])); } return from(codings.bind()); } public static Parser<TransferEncoding> parseHttpValue(Input input, HttpParser http) { return TransferEncodingParser.parse(input, http); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/TransferEncodingParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.collections.FingerTrieSeq; import swim.http.Http; import swim.http.HttpParser; import swim.http.TransferCoding; import swim.util.Builder; final class TransferEncodingParser extends Parser<TransferEncoding> { final HttpParser http; final Parser<TransferCoding> coding; final Builder<TransferCoding, FingerTrieSeq<TransferCoding>> codings; final int step; TransferEncodingParser(HttpParser http, Parser<TransferCoding> coding, Builder<TransferCoding, FingerTrieSeq<TransferCoding>> codings, int step) { this.http = http; this.coding = coding; this.codings = codings; this.step = step; } TransferEncodingParser(HttpParser http) { this(http, null, null, 1); } @Override public Parser<TransferEncoding> feed(Input input) { return parse(input, this.http, this.coding, this.codings, this.step); } static Parser<TransferEncoding> parse(Input input, HttpParser http, Parser<TransferCoding> coding, Builder<TransferCoding, FingerTrieSeq<TransferCoding>> codings, int step) { int c = 0; if (step == 1) { if (coding == null) { coding = http.parseTransferCoding(input); } else { coding = coding.feed(input); } if (coding.isDone()) { if (codings == null) { codings = FingerTrieSeq.builder(); } codings.add(coding.bind()); coding = null; step = 2; } else if (coding.isError()) { return coding.asError(); } } do { if (step == 2) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont() && c == ',') { input = input.step(); step = 3; } else if (!input.isEmpty()) { return done(TransferEncoding.from(codings.bind())); } } if (step == 3) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { step = 4; } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } if (step == 4) { if (coding == null) { coding = http.parseTransferCoding(input); } else { coding = coding.feed(input); } if (coding.isDone()) { codings.add(coding.bind()); coding = null; step = 2; continue; } else if (coding.isError()) { return coding.asError(); } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new TransferEncodingParser(http, coding, codings, step); } static Parser<TransferEncoding> parse(Input input, HttpParser http) { return parse(input, http, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/Upgrade.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Writer; import swim.collections.FingerTrieSeq; import swim.http.HttpHeader; import swim.http.HttpParser; import swim.http.HttpWriter; import swim.http.UpgradeProtocol; import swim.util.Builder; import swim.util.Murmur3; public final class Upgrade extends HttpHeader { final FingerTrieSeq<UpgradeProtocol> protocols; Upgrade(FingerTrieSeq<UpgradeProtocol> protocols) { this.protocols = protocols; } @Override public String lowerCaseName() { return "upgrade"; } @Override public String name() { return "Upgrade"; } public FingerTrieSeq<UpgradeProtocol> protocols() { return this.protocols; } public boolean supports(UpgradeProtocol protocol) { final FingerTrieSeq<UpgradeProtocol> protocols = this.protocols; for (int i = 0, n = protocols.size(); i < n; i += 1) { if (protocol.matches(protocols.get(i))) { return true; } } return false; } @Override public Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http) { return http.writeParamList(this.protocols.iterator(), output); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof Upgrade) { final Upgrade that = (Upgrade) other; return this.protocols.equals(that.protocols); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(Upgrade.class); } return Murmur3.mash(Murmur3.mix(hashSeed, this.protocols.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("Upgrade").write('.').write("from").write('('); final int n = this.protocols.size(); if (n > 0) { output.debug(this.protocols.head()); for (int i = 1; i < n; i += 1) { output = output.write(", ").debug(this.protocols.get(i)); } } output = output.write(')'); } private static int hashSeed; private static Upgrade websocket; public static Upgrade websocket() { if (websocket == null) { websocket = new Upgrade(FingerTrieSeq.of(UpgradeProtocol.websocket())); } return websocket; } public static Upgrade from(FingerTrieSeq<UpgradeProtocol> protocols) { if (protocols.size() == 1) { final UpgradeProtocol protocol = protocols.head(); if (protocol == UpgradeProtocol.websocket()) { return websocket(); } } return new Upgrade(protocols); } public static Upgrade from(UpgradeProtocol... protocols) { return from(FingerTrieSeq.of(protocols)); } public static Upgrade from(String... protocolStrings) { final Builder<UpgradeProtocol, FingerTrieSeq<UpgradeProtocol>> protocols = FingerTrieSeq.builder(); for (int i = 0, n = protocolStrings.length; i < n; i += 1) { protocols.add(UpgradeProtocol.parse(protocolStrings[i])); } return from(protocols.bind()); } public static Parser<Upgrade> parseHttpValue(Input input, HttpParser http) { return UpgradeParser.parse(input, http); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/UpgradeParser.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Diagnostic; import swim.codec.Input; import swim.codec.Parser; import swim.collections.FingerTrieSeq; import swim.http.Http; import swim.http.HttpParser; import swim.http.UpgradeProtocol; import swim.util.Builder; final class UpgradeParser extends Parser<Upgrade> { final HttpParser http; final Parser<UpgradeProtocol> protocol; final Builder<UpgradeProtocol, FingerTrieSeq<UpgradeProtocol>> protocols; final int step; UpgradeParser(HttpParser http, Parser<UpgradeProtocol> protocol, Builder<UpgradeProtocol, FingerTrieSeq<UpgradeProtocol>> protocols, int step) { this.http = http; this.protocol = protocol; this.protocols = protocols; this.step = step; } UpgradeParser(HttpParser http) { this(http, null, null, 1); } @Override public Parser<Upgrade> feed(Input input) { return parse(input, this.http, this.protocol, this.protocols, this.step); } static Parser<Upgrade> parse(Input input, HttpParser http, Parser<UpgradeProtocol> protocol, Builder<UpgradeProtocol, FingerTrieSeq<UpgradeProtocol>> protocols, int step) { int c = 0; if (step == 1) { if (protocol == null) { protocol = http.parseUpgradeProtocol(input); } else { protocol = protocol.feed(input); } if (protocol.isDone()) { if (protocols == null) { protocols = FingerTrieSeq.builder(); } protocols.add(protocol.bind()); protocol = null; step = 2; } else if (protocol.isError()) { return protocol.asError(); } } do { if (step == 2) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont() && c == ',') { input = input.step(); step = 3; } else if (!input.isEmpty()) { return done(Upgrade.from(protocols.bind())); } } if (step == 3) { while (input.isCont()) { c = input.head(); if (Http.isSpace(c)) { input = input.step(); } else { break; } } if (input.isCont()) { step = 4; } else if (input.isDone()) { return error(Diagnostic.unexpected(input)); } } if (step == 4) { if (protocol == null) { protocol = http.parseUpgradeProtocol(input); } else { protocol = protocol.feed(input); } if (protocol.isDone()) { protocols.add(protocol.bind()); protocol = null; step = 2; continue; } else if (protocol.isError()) { return protocol.asError(); } } break; } while (true); if (input.isError()) { return error(input.trap()); } return new UpgradeParser(http, protocol, protocols, step); } static Parser<Upgrade> parse(Input input, HttpParser http) { return parse(input, http, null, null, 1); } }
0
java-sources/ai/swim/swim-http/3.10.0/swim/http
java-sources/ai/swim/swim-http/3.10.0/swim/http/header/UserAgent.java
// Copyright 2015-2019 SWIM.AI inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package swim.http.header; import swim.codec.Input; import swim.codec.Output; import swim.codec.Parser; import swim.codec.Writer; import swim.collections.FingerTrieSeq; import swim.http.HttpHeader; import swim.http.HttpParser; import swim.http.HttpWriter; import swim.http.Product; import swim.util.Builder; import swim.util.Murmur3; public final class UserAgent extends HttpHeader { final FingerTrieSeq<Product> products; UserAgent(FingerTrieSeq<Product> products) { this.products = products; } @Override public String lowerCaseName() { return "user-agent"; } @Override public String name() { return "User-Agent"; } public FingerTrieSeq<Product> products() { return this.products; } @Override public Writer<?, ?> writeHttpValue(Output<?> output, HttpWriter http) { return UserAgentWriter.write(output, http, this.products.iterator()); } @Override public boolean equals(Object other) { if (this == other) { return true; } else if (other instanceof UserAgent) { final UserAgent that = (UserAgent) other; return this.products.equals(that.products); } return false; } @Override public int hashCode() { if (hashSeed == 0) { hashSeed = Murmur3.seed(UserAgent.class); } return Murmur3.mash(Murmur3.mix(hashSeed, this.products.hashCode())); } @Override public void debug(Output<?> output) { output = output.write("UserAgent").write('.').write("from").write('('); final int n = this.products.size(); if (n > 0) { output.debug(this.products.head()); for (int i = 1; i < n; i += 1) { output = output.write(", ").debug(this.products.get(i)); } } output = output.write(')'); } private static int hashSeed; public static UserAgent from(FingerTrieSeq<Product> products) { return new UserAgent(products); } public static UserAgent from(Product... products) { return new UserAgent(FingerTrieSeq.of(products)); } public static UserAgent from(String... productStrings) { final Builder<Product, FingerTrieSeq<Product>> products = FingerTrieSeq.builder(); for (int i = 0, n = productStrings.length; i < n; i += 1) { products.add(Product.parse(productStrings[i])); } return new UserAgent(products.bind()); } public static Parser<UserAgent> parseHttpValue(Input input, HttpParser http) { return UserAgentParser.parse(input, http); } }