这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@AndreiTelteu
Copy link

I use Laravel Herd as my local webserver because you get local valid ssl and it's easy do use and update, and since it uses nginx virtual hosts to switch between the websites I was not able to proxy to the correct website:

Problem 1: I need to replace localhost with sitename.test
Problem 2: I need to replace http with https, it can work with http as well but it's nicer to use https

In this PR I added 2 new flags:

  • -local-proto that should get http or https
  • -local-host to enter the hostname, or virtual host you want to access

I ran the tests and it passes, but with a panic:

2025/06/23 20:53:56 [zirvkx] "POST /post HTTP/1.1" 408 28
2025/06/23 20:54:23 [zirvkx] "GET /long-running HTTP/1.1" 200 43
2025/06/23 20:54:23 http: panic serving 127.0.0.1:55290: crashing devserver
goroutine 186 [running]:
net/http.(*conn).serve.func1()
        /home/andrei/.local/opt/go-v1.23.4/src/net/http/server.go:1947 +0xbe
panic({0x749a40?, 0x8589b0?})
        /home/andrei/.local/opt/go-v1.23.4/src/runtime/panic.go:785 +0x132
github.com/yusuf-musleh/mmar/simulations/devserver.handleCrashingReq({0xc0002000a0?, 0x478632?}, 0xc000277b38?)
        /home/andrei/mmar/simulations/devserver/main.go:224 +0x25
net/http.HandlerFunc.ServeHTTP(0xc00016a0e0?, {0x85c9f0?, 0xc00016a1c0?}, 0x6e7e36?)
        /home/andrei/.local/opt/go-v1.23.4/src/net/http/server.go:2220 +0x29
net/http.(*ServeMux).ServeHTTP(0x46bf79?, {0x85c9f0, 0xc00016a1c0}, 0xc000170280)
        /home/andrei/.local/opt/go-v1.23.4/src/net/http/server.go:2747 +0x1ca
net/http.serverHandler.ServeHTTP({0xc000202390?}, {0x85c9f0?, 0xc00016a1c0?}, 0x6?)
        /home/andrei/.local/opt/go-v1.23.4/src/net/http/server.go:3210 +0x8e
net/http.(*conn).serve(0xc0000e6090, {0x85cdf0, 0xc0002020f0})
        /home/andrei/.local/opt/go-v1.23.4/src/net/http/server.go:2092 +0x5d0
created by net/http.(*Server).Serve in goroutine 21
        /home/andrei/.local/opt/go-v1.23.4/src/net/http/server.go:3360 +0x485
2025/06/23 20:54:23 [zirvkx] "GET /crash HTTP/1.1" 200 59

Or is this a normal test case scenario since the request was GET /crash ?

I am new to golang testing. How would I write a test for this new flags ?
To test the hostname change should I edit the /etc/hosts ? I think no.
Should I test using an external dns that resolves to localhost ? https://nip.io/ or https://sslip.io/

replace original module name

change log message to reflect new parameters localProto and localHost

overwrite host
Copy link
Owner

@yusuf-musleh yusuf-musleh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @AndreiTelteu ! Thanks a lot for the contribution, and apologies for the late response, been a way for some time.

This is a good use case I haven't thought of, and would like to get it merged. Regarding your questions about tests:

Or is this a normal test case scenario since the request was GET /crash ?

Yes, that panic is expected as I am making sure mmar handles it gracefully if the devserver crashes.

I am new to golang testing. How would I write a test for this new flags ?
To test the hostname change should I edit the /etc/hosts ? I think no.
Should I test using an external dns that resolves to localhost ? https://nip.io/ or https://sslip.io/

That's a good question, in general I wanted to avoid any dependancies and making changes to local files/envs when working with mmar including when writing tests. In fact, I built a basic DNS server that runs with the simulation tests in order to avoid depending on external tools like the ones you mentioned, it resolves every address to the loopback address. (I also wrote a blog post about it incase you are interested in reading more). So we can make use of that basic DNS server (through the new flags added to mmar client, see below) in the tests.

Now in order to test these new flags, I made some changes to the tests:

  • It now runs a dev server with TLS with the address of example.com (by default golang's testhttp TLS server only generates certificates for *.example.com), the generated certificate is written to a temp file that the mmar client can later make use of through the new --custom-cert flag. Currently this server is not being used, but you can use it in the tests for this PR.

  • The tests also allows running multiple mmar clients, and they now accepts extra flags. For your tests, you can create a new mmar and pass in the appropriate parameters. It would looks something like this:

httpsClientUrlCh := make(chan string)
go StartMmarClient(simulationCtx, httpsClientUrlCh, localDevServer.Port(), "example.com", "https", "127.0.0.1:3535", "./temp-cert")

This passes in the basic DNS we have running to the --custom-dns flag and the temp cert file to the --custom-cert flag in the mmar client. Then you'd need to update the mmar client below it to make sure all the tests run.

Let me know if you have any questions or pointers, I'd be happy to help, and would love to help you get this merged!

Comment on lines -68 to 72

The fastest way to create a tunnel what is running on your `localhost:8080` using [Docker](https://www.docker.com/) is by running this command:
The fastest way to create a tunnel what is running on your `https://project.test:443` using [Docker](https://www.docker.com/) is by running this command:

```
docker run --rm --network host ghcr.io/yusuf-musleh/mmar:v0.2.6 client --local-port 8080
docker run --rm --network host ghcr.io/yusuf-musleh/mmar:v0.2.6 client --local-proto https --local-host project.test --local-port 443
```
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably add it as an additional instruction/command rather than replacing this one, as this example is likely more common for users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants