Closes #27641 This PR fixes invalid proxy URIs being registered despite the URI not being a valid proxy URI. Whilst investigating #27641 , I noticed that currently any proxy URI passed to `RequestClient::proxy_and_user_agent` will be assigned to the created client, even if the URI is not a valid proxy URI. Given a test as an example: We create an URI here and pass it as a proxy to `ReqwestClient::proxy_and_user_agent`: https://github.com/zed-industries/zed/blob/main/crates/reqwest_client/src/reqwest_client.rs#L272-L273 In `ReqwestClient::proxy_and_user_agent`we take the proxy parameter here https://github.com/zed-industries/zed/blob/9b40770e9f92a4431fe8f04cbb03b106569606c8/crates/reqwest_client/src/reqwest_client.rs#L46 and set it unconditionally here: https://github.com/zed-industries/zed/blob/9b40770e9f92a4431fe8f04cbb03b106569606c8/crates/reqwest_client/src/reqwest_client.rs#L62 , not considering at all whether the proxy was successfully created above. Concluding, we currently do not actually check whether a proxy was successfully created, but rather whether an URI is equal to itself, which trivially holds. The existing test for a malformed proxy URI https://github.com/zed-industries/zed/blob/9b40770e9f92a4431fe8f04cbb03b106569606c8/crates/reqwest_client/src/reqwest_client.rs#L293-L297 does not check whether invalid proxies cause an error, but rather checks whether `http::Uri::from_static` panics on an invalid URI, [which it does as documented](https://docs.rs/http/latest/http/uri/struct.Uri.html#panics). Thus, the tests currently do not really check anything proxy-related and invalid proxies are assigned as valid proxies. --- This PR fixes the behaviour by considering whether the proxy was actually properly parsed and only assigning it if that is the case. Furthermore, it improves logging in case of errors so issues like the linked one are easier to debug (for the linked issue, the log will now include that the proxy schema is not supported in the logs). Lastly, it also updates the test for a malformed proxy URI. The test now actually checks that malformed proxy URIs are not registered for the client rather than testing the `http` crate. The update also initially caused the [test for a `socks4a` proxy](https://github.com/zed-industries/zed/blob/9b40770e9f92a4431fe8f04cbb03b106569606c8/crates/reqwest_client/src/reqwest_client.rs#L280C1-L282C50) to fail. This happened because the reqwest-library introduced supports for `socks4a` proxies in [version 0.12.13](https://github.com/seanmonstar/reqwest/blob/master/CHANGELOG.md#v01213). Thus, this PR includes a bump of the reqwest library to add proper support for socks4a proxies. Release Notes: - Added support for socks4a proxies. --------- Co-authored-by: Peter Tripp <peter@zed.dev>
Welcome to GPUI!
GPUI is a hybrid immediate and retained mode, GPU accelerated, UI framework for Rust, designed to support a wide variety of applications.
Getting Started
GPUI is still in active development as we work on the Zed code editor and isn't yet on crates.io. You'll also need to use the latest version of stable Rust and be on macOS or Linux. Add the following to your Cargo.toml:
gpui = { git = "https://github.com/zed-industries/zed" }
Everything in GPUI starts with an Application. You can create one with Application::new(), and kick off your application by passing a callback to Application::run(). Inside this callback, you can create a new window with App::open_window(), and register your first root view. See gpui.rs for a complete example.
Dependencies
GPUI has various system dependencies that it needs in order to work.
macOS
On macOS, GPUI uses Metal for rendering. In order to use Metal, you need to do the following:
- Install Xcode from the macOS App Store, or from the Apple Developer website. Note this requires a developer account.
Ensure you launch XCode after installing, and install the macOS components, which is the default option.
-
Install Xcode command line tools
xcode-select --install -
Ensure that the Xcode command line tools are using your newly installed copy of Xcode:
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
The Big Picture
GPUI offers three different registers depending on your needs:
-
State management and communication with
Entity's. Whenever you need to store application state that communicates between different parts of your application, you'll want to use GPUI's entities. Entities are owned by GPUI and are only accessible through an owned smart pointer similar to anRc. See theapp::contextmodule for more information. -
High level, declarative UI with views. All UI in GPUI starts with a view. A view is simply an
Entitythat can be rendered, by implementing theRendertrait. At the start of each frame, GPUI will call this render method on the root view of a given window. Views build a tree ofelements, lay them out and style them with a tailwind-style API, and then give them to GPUI to turn into pixels. See thedivelement for an all purpose swiss-army knife of rendering. -
Low level, imperative UI with Elements. Elements are the building blocks of UI in GPUI, and they provide a nice wrapper around an imperative API that provides as much flexibility and control as you need. Elements have total control over how they and their child elements are rendered and can be used for making efficient views into large lists, implement custom layouting for a code editor, and anything else you can think of. See the
elementmodule for more information.
Each of these registers has one or more corresponding contexts that can be accessed from all GPUI services. This context is your main interface to GPUI, and is used extensively throughout the framework.
Other Resources
In addition to the systems above, GPUI provides a range of smaller services that are useful for building complex applications:
-
Actions are user-defined structs that are used for converting keystrokes into logical operations in your UI. Use this for implementing keyboard shortcuts, such as cmd-q. See the
actionmodule for more information. -
Platform services, such as
quit the apporopen a URLare available as methods on theapp::App. -
An async executor that is integrated with the platform's event loop. See the
executormodule for more information., -
The
[gpui::test]macro provides a convenient way to write tests for your GPUI applications. Tests also have their own kind of context, aTestAppContextwhich provides ways of simulating common platform input. Seeapp::test_contextandtestmodules for more details.
Currently, the best way to learn about these APIs is to read the Zed source code, ask us about it at a fireside hack, or drop a question in the Zed Discord. We're working on improving the documentation, creating more examples, and will be publishing more guides to GPUI on our blog.