1

I want to send multiple requests to my localhost:3000 server from various clients, and I want to simulate that scenario. I'm using the clj-http library to make a request:

(client/get "http://localhost:3000/")

How do I make the request from an ip address other than 127.0.0.1?

zendevil.eth
  • 974
  • 2
  • 9
  • 28
  • You can use all the addresses in the `127.0.0.0/8` block. The entire block has loopback addresses, although most people just use `127.0.0.1`. You can use any or all of them to test from one to the other. By the way, IPv6 has only one loopback address: `::1`. – Ron Maupin May 03 '21 at 01:04
  • 2
    Do you need to use actual network traffic? A Ring handler is just a function from request to response, and it's easy to call that function with a request that claims to be from any address you like. – amalloy May 03 '21 at 07:24
  • what's your purpose of this, will your server program behaves differently? – Jack Wu Jun 01 '21 at 15:34
  • there's supposed to be a kubernetes ingress load balancer that routes the request to one of the replicas based on the client id in the header of the request – zendevil.eth Jun 01 '21 at 16:34

3 Answers3

0

One simple answer is to fire up a linux VM in VirtualBox (either directly or by using Vagrant), then make the request from the VM.

Vagrant is an easy-to-use driver since the config files (i.e. Vagrantfile) is simple text and can be checked into git. You can control the IP address of the VM with a simple entry like

config.vm.network "private_network", ip: "192.168.50.4"

See both the

(note that they are in 2 different locations!)

Alan Thompson
  • 29,276
  • 6
  • 41
  • 48
0

Another option could be to have a simple client as a Docker image (or combination of base image and a custom command) and you can launch them fairly quickly. See this answer for some guidance: https://stackoverflow.com/a/24326540/483566

Denis Fuenzalida
  • 3,271
  • 1
  • 17
  • 22
0

What exactly are you testing? If it's a unit test, send a request to the handler with the desired IP address in the data structure.

If it's an integration test, spin up a server, and use the java library org.apache.http to hit the end points.

To spin up the server use the once fixture. It looks similar to this

(use-fixtures :once
              (fn [tests]
                (before stuff) ;start server here
                (tests)
                (after stuff))) ;shut down server here

This is the org.apache.http documentation. This is the subpage you'll want to look at. Read about setting the Requests. You'll want to set the IP address in the header of a request and then send it. Baeldung shows examples of using org.apache.http in java. which you can translate into Clojure code

triplej
  • 269
  • 4
  • 9