Patitotective / ImThemes

Dear ImGui style browser and editor written in Nim
MIT License
348 stars 74 forks source link

Proxy support? #21

Open damntourists opened 1 year ago

damntourists commented 1 year ago

I'd like to request proxy support if possible. I have to get off of the company VPN in order to use this app successfully. Love your app <3.

Patitotective commented 1 year ago

Hi. I've never implemented a proxy myself and after checking some documentation it seems that providing it as an environmental variable (e.g.: http_proxy or https_proxy) is possible. There also seems to be an authentication option like user:password, it could as well be provided by an environmental variable proxy_auth. Would these two options be sufficient? If not could you tell me how proxy support is normally implemented. Thank you.

Madam-Herta commented 10 months ago

Hi. I've never implemented a proxy myself and after checking some documentation it seems that providing it as an environmental variable (e.g.: http_proxy or https_proxy) is possible. There also seems to be an authentication option like user:password, it could as well be provided by an environmental variable proxy_auth. Would these two options be sufficient? If not could you tell me how proxy support is normally implemented. Thank you.

You can use the httpbeast library, which provides easy-to-use HTTP client capabilities, including proxy support. You can install it using Nim's package manager Nimble if you haven't already:

nimble install httpbeast

Here's a basic example of how you can make an HTTP request through a proxy in a Nim application:

import httpbeast, asyncdispatch

proc main() {.async.} =
  # Define the proxy settings
  let proxy = Proxy(kind: HttpProxy, host: "your_proxy_host", port: 8080, username: "your_username", password: "your_password")

  # Create an HTTP client with the proxy settings
  let client = newAsyncHttpClient(proxy: proxy)

  # Define the URL you want to fetch through the proxy
  let url = "https://example.com"

  try:
    # Make an HTTP GET request
    let response = await client.get(url)

    # Check the response status
    if response.status == 200:
      echo("Success: ", response.body)
    else:
      echo("Failed with status code: ", response.status)
  except HttpException as e:
    echo("HTTP request error: ", e.msg)

asyncCheck main()

In this example:

Make sure to replace "your_proxy_host", 8080, "your_username", and "your_password" with the actual proxy server details you want to use.

Well, depending on your specific use case, you may need to customize the code further, handle exceptions, and add error handling.