apple / swift-nio-examples Goto Github PK
View Code? Open in Web Editor NEWexamples of how to use swift-nio
License: Apache License 2.0
examples of how to use swift-nio
License: Apache License 2.0
2020-12-08T10:18:44+0700 error com.apple.nio-connect-proxy.ConnectHandler : remoteAddress=Optional([IPv4]127.0.0.1/127.0.0.1:51759) localAddress=Optional([IPv4]127.0.0.1/127.0.0.1:9090) channel=ObjectIdentifier(0x000000010840c7a0) Connect failed: NIOConnectionError(host: "in.appcenter.ms", port: 443, dnsAError: Optional(NIO.SocketAddressError.unknown(host: "in.appcenter.ms", port: 443)), dnsAAAAError: Optional(NIO.SocketAddressError.unknown(host: "in.appcenter.ms", port: 443)), connectionErrors: [])
2020-12-08T10:18:44+0700 error com.apple.nio-connect-proxy.ConnectHandler : channel=ObjectIdentifier(0x0000000100c0b770) remoteAddress=Optional([IPv4]127.0.0.1/127.0.0.1:51760) localAddress=Optional([IPv4]127.0.0.1/127.0.0.1:9090) Connect failed: NIOConnectionError(host: "google.com", port: 443, dnsAError: Optional(NIO.SocketAddressError.unknown(host: "google.com", port: 443)), dnsAAAAError: Optional(NIO.SocketAddressError.unknown(host: "google.com", port: 443)), connectionErrors: [])
2020-12-08T10:18:44+0700 error com.apple.nio-connect-proxy.ConnectHandler : remoteAddress=Optional([IPv4]127.0.0.1/127.0.0.1:51855) localAddress=Optional([IPv4]127.0.0.1/127.0.0.1:9090) channel=ObjectIdentifier(0x000000010800a3a0) Connect failed: connectTimeout(NIO.TimeAmount(nanoseconds: 10000000000))
cloudflare-https.mobileconfig
on Big Sur macOSconnect-proxy
at port 9090swift --version && uname -a
)Apple Swift version 5.3.1 (swiftlang-1200.0.41 clang-1200.0.32.8)
Target: x86_64-apple-darwin20.1.0
Darwin Nghias-MacBook-Pro.local 20.1.0 Darwin Kernel Version 20.1.0: Sat Oct 31 00:07:11 PDT 2020; root:xnu-7195.50.7~2/RELEASE_X86_64 x86_64
Thank Swift NIO team for developing a powerful tool ๐
Right now, NIOTLS only supports two legacy/deprecated versions of SMTP:
It should support STARTTLS
too. That change won't be very hard but it will need to be implemented using swift-nio-ssl
instead of Network.framework's TLS because Network.framework's TLS doesn't support STARTTLS
.
connect-proxy should have a readme on how to use it. Maybe also some screenshots on how to configure your Mac to use it
We have a code generator for Swift that is based on the JSON RPC example here. However, the asynchronous nature is causing maintainability headaches for us. For example, we need to make several JSON RPC calls to retrieve values from the other process, and we need to wait until all of the values have been successfully retrieved before we continue. Currently, the working solution for this produces an ugly pyramid-of-doom:
get(value: "1") {
get(value: "2") {
get(value: "3") {
// etc. and then finally
completion()
}
}
}
There are over a dozen values we need to get, so this is clearly not what we want. We really just want something like:
group = DispatchGroup()
for key in keys {
group.enter()
let future = channel.call(method: "GetValue": params: .list([.string(session), .string(key)]))
future.whenSuccess { result in
switch result {
case let .success(response):
let value = response.asString
self.args[key] = value
case .failure:
break
}
group.leave()
}
}
group.wait()
completion()
However, this just hangs. Trying to use group.notify(DispatchQueue.global()) { completion() }
seemingly works but then the next RPC call fails:
Precondition failed: file /Users/.../.build/checkouts/swift-nio/Sources/NIO/ChannelPipeline.swift, line 158
The following PR in the swift-nio repo added convenience API for blocking semantics to Swift NIO: apple/swift-nio#1563
Could you provide an example of how Client.call(method:params)
(https://github.com/apple/swift-nio-examples/blob/main/json-rpc/Sources/JsonRpc/Client.swift#L60) can be rewritten to use these blocking semantics such that RPC calls are essentially synchronous?
On receiving a bad / unsupported request, return a 400 response
It just hangs, no response, and leaves the socket open.
$ curl -gvsS --proxy localhost:8080 http://example.com/
swift --version && uname -a
)Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53)
Target: x86_64-apple-darwin19.5.0
Darwin Noahs-MacBook-Pro-16-inch-2019 19.5.0 Darwin Kernel Version 19.5.0: Tue May 26 20:41:44 PDT 2020; root:xnu-6153.121.2~2/RELEASE_X86_64 x86_64
Maybe I can help out with this as I need to build soon this myself.
we should have a short HTTP server example that does
and it should live in this repository so we can depend on the other NIO parts. This should supersede NIOHTTP1Server
as the example we point people to.
Passing a URL with an IP address as an argument to http2-client
results in a fatal error, because creating NIOSSLClientHandler
is assumed never to fail.
Yes, I know this can be worked around by passing serverHostname: nil
to the NIOSSLClientHandler
constructor, but then SNI will be disabled altogether.
Even if URLs with IP addresses are not a typical use case with HTTPS, I think this example code should set an example on what to do with IP addresses, and not just crash.
Error about failing to verify certificate, but no fatal error.
Fatal error: 'try!' expression unexpectedly raised an error: NIOSSLExtraError.cannotUseIPAddressInSNI: IP addresses cannot validly be used for Server Name Indication, got 192.168.0.1: file http2_client/main.swift, line 305
zsh: illegal hardware instruction swift run http2-client https://192.168.0.1/
% swift run http2-client https://192.168.0.1/
(doesn't matter if there's a server running at that IP or not)[anything to help us reproducing the issue]
swift --version && uname -a
)Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)
Target: x86_64-apple-darwin19.6.0
Darwin MiniII.lan 19.6.0 Darwin Kernel Version 19.6.0: Tue Jun 22 19:49:55 PDT 2021; root:xnu-6153.141.35~1/RELEASE_X86_64 x86_64
Unclean TLS shutdown should be ignored when the request has been fully delivered.
Unclean TLS shutdown is reported in the terminal.
https://microsoft.com
Hi, this week, I've encountered some strange issues when trying proxy the HTTPS connection from Android Emulator. I tried, but I haven't found an answer yet. I hope by opening this ticket here, someone can help me.
Thanks for your hard work on the SwiftNIO project ๐
8.8.8.8:853
is hangcurl -v "https://httpbin.proxyman.app/get?id=123" --proxy localhost:8080
channedRead
is called โ
โก๏ธ [GlueHandler] handlerAdded
๐ [GlueHandler] channelRead, data = \(data)
CONNECT 8.8.8.8:853 HTTP/1.1
connect-proxy
returns HTTP/1.1 200 OK
I guess the connect-proxy doesn't support TCP yet, but if you don't mind, can you point out how to support it? I tried to add a new TCPHandler to read the data, but there is no readable data is called.
Video: https://drive.google.com/file/d/1ojOtRa-15N_pPklrApIFAAhX3xYfeQ2i/view?usp=sharing
The latest version of connect-proxy example.
swift --version && uname -a
)swift-nio-examples/json-rpc/Sources/JsonRpc/Client.swift
Lines 20 to 60 in d36c05a
Thanks to @wlisac for the report.
At least TCPClient
is very thread unsafe and really needs fixing. Without synchronisation, state
is read/written to from different threads.
when using connect proxy demo to access 'http://sns-img-hw.xhscdn.com/1040g00830ntikh5h1a005odf8lgoceh3uoecgn8?imageView2/2/w/540/format/jpg/q/75%7CimageMogr2/strip&redImage/frame/0' , the logger show Invalid HTTP message type get.
we don't publish API docs for swift-nio-extras at the moment...
NIOSMTP's should escape things like names and the body of an email so you can send anything without errors.
Nothing is escaped, for example putting an line just containing a full stop (.
) in an email will cause an SMTP protocol error. The emails should be properly MIME encoded instead.
Try to send an email with NIOSMTP containing a line with just a full stop.
Error about connection being refused, no fatal error.
ERROR: NIOConnectionError(host: "localhost", port: 443, dnsAError: nil, dnsAAAAError: nil, connectionErrors: [NIO.SingleConnectionFailure(target: [IPv6]localhost/::1:443, error: connection reset (error set): Connection refused (errno: 61)), NIO.SingleConnectionFailure(target: [IPv4]localhost/127.0.0.1:443, error: connection reset (error set): Connection refused (errno: 61))])
Fatal error: leaking promise created at (file: "/Users/lauri/Documents/swift-nio-examples/http2-client/Sources/http2-client/main.swift", line: 298): file /Users/lauri/Documents/swift-nio-examples/http2-client/Sources/http2-client/main.swift, line 298
zsh: illegal hardware instruction swift run http2-client https://localhost/
swift run http2-client https://localhost/
[anything to help us reproducing the issue]
swift --version && uname -a
)Apple Swift version 5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28)
Target: x86_64-apple-darwin19.6.0
Darwin MiniII.lan 19.6.0 Darwin Kernel Version 19.6.0: Tue Jun 22 19:49:55 PDT 2021; root:xnu-6153.141.35~1/RELEASE_X86_64 x86_64
the JSONRPC example codecs should move into swift-nio-extras
I would like to use the JSONRPC codecs in a project of mine.
While the json-rpc folder contains a Package.swift
file, it is of no use since a Swift package seems to be defined by a repository where Package.swift
is placed in the root.
Is there any other recommended way to use the JSONRPC code besides just copying it into my project?
My use case is only academic/experimental and I am aware that this repository only contains example code that should not be used without further review.
SMTPResponseDecoder
should include a comment explaining why in this case ChannelInboundHandler
was used instead of ByteToMessageDecoder
.
SMTPResponseDecoder
lacks documentation about that.
[what you expected to happen]
build success
[what actually happened]
Resolving https://github.com/apple/swift-nio at 2.18.0
In file included from /Users/aeris/hswork/http2/swift-nio-examples/http2-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/ssl/tls_record.cc:109:
In file included from /Users/aeris/hswork/http2/swift-nio-examples/http2-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/include/CNIOBoringSSL_ssl.h:145:
/Users/aeris/hswork/http2/swift-nio-examples/http2-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/include/CNIOBoringSSL_base.h:478:10: fatal error: 'memory' file not found
#include <memory>
^~~~~~~~
In file included from /Users/aeris/hswork/http2/swift-nio-examples/http2-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/ssl/tls13_enc.cc:15:
In file included from /Users/aeris/hswork/http2/swift-nio-examples/http2-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/include/CNIOBoringSSL_ssl.h:145:
/Users/aeris/hswork/http2/swift-nio-examples/http2-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/include/CNIOBoringSSL_base.h:478:10: fatal er
In file included from /Users/aeris/hswork/http2/swift-nio-examples/http2-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/ssl/tls_method.cc:57:
In file included from /Users/aeris/hswork/http2/swift-nio-examples/http2-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/include/CNIOBoringSSL_ssl.h:145:
/Users/aeris/hswork/http2/swift-nio-examples/http2-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/include/CNIOBoringSSL_base.h:478:10: fatal error: 'memory' file not found
#include <memory>
^~~~~~~~
In file included from /Users/aeris/hswork/http2/swift-nio-examples/http2-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/ssl/tls13_server.cc:15:
In file included from /Users/aeris/hswork/http2/swift-nio-examples/http2-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/include/CNIOBoringSSL_ssl.h:145:
^~~~~~~~
1 error generated.
1 error generated.
[6/435] Compiling tls_method.cc
[anything to help us reproducing the issue]
[tag/commit hash]
swift --version && uname -a
)swift version: swift/5.2.4
macos:10.15.4
json-rpc is missing license headers.
Failure to negotiate HTTP/2 should either be reported, or tolerated.
http2-client ignores the failure to negotiate HTTP/2 and just sends it anyway, leading to errors.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.