Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxy support? #21

Open
damntourists opened this issue Aug 16, 2023 · 2 comments
Open

Proxy support? #21

damntourists opened this issue Aug 16, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@damntourists
Copy link

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
Copy link
Owner

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.

@Patitotective Patitotective self-assigned this Aug 24, 2023
@Patitotective Patitotective added the enhancement New feature or request label Aug 24, 2023
Patitotective added a commit that referenced this issue Aug 24, 2023
@Madam-Herta
Copy link
Contributor

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:

  • We import the httpbeast and asyncdispatch modules.
  • We define the proxy settings using the Proxy type, specifying the proxy type (HttpProxy), host, port, and, if needed, a username and password for authentication.
  • We create an HTTP client using newAsyncHttpClient and pass the proxy settings.
  • We define the URL you want to fetch through the proxy.
  • We make an HTTP GET request using client.get(url).
  • We check the response status and handle the result accordingly.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants