Skip to content

Added support for proxy url#361

Open
voldyman wants to merge 1 commit intoForceu:masterfrom
voldyman:master
Open

Added support for proxy url#361
voldyman wants to merge 1 commit intoForceu:masterfrom
voldyman:master

Conversation

@voldyman
Copy link

@voldyman voldyman commented Feb 7, 2026

I run gokapi behind a Caddy server using reverse proxy as well as on my local network. Both setups have different hostnames and currently Gokapi only supports using one "public hostname" which leads to one endpoint failing to download (downloadPresigned uses the configured url).

This changes add support for respecting the X-Forwarded-* headers to respond with the appropriate hostname and fixes the issue.

@Forceu
Copy link
Owner

Forceu commented Feb 9, 2026

Thank you for your PR. Has there been any AI involved in this PR?

@voldyman
Copy link
Author

voldyman commented Feb 9, 2026

Only when I was trying to figure out why the reverse proxy config in my Caddyfile wasn't working and the generated url used the internal hostname.
The code was written by hand and tested by had in my setup. I guess AI wouldn't have forgotten to fix the tests 😅

@Forceu
Copy link
Owner

Forceu commented Feb 9, 2026

Thank you for the quick response :) I would prefer not to add httpRequest *http.Request to all API entries, as the httpRequest is already submitted with requestParser.ProcessParameter(r *http.Request) error, which is called for all API entries. (Which would also make the reviewing of this PR a lot easier) ;)

If an API call requires the http.Request, you can add it to it's struct, which can for example been seen here:

type paramFilesAdd struct {
Request *http.Request
}
func (p *paramFilesAdd) ProcessParameter(r *http.Request) error {
p.Request = r
return nil
}

@voldyman
Copy link
Author

voldyman commented Feb 9, 2026

Gotcha, another option was to route the X-Forwarded-For value in the context and wire the context through the API.

  • the X-Forwarded-For is higher level information than the request data for each request type
  • although it'll keep the PR as sprawling as it is now

Which one do you prefer? i can update the PR after work today.

@Forceu
Copy link
Owner

Forceu commented Feb 9, 2026

I think the best way would be to include the *http.Request and pass it to the new function that returns the server URL. The default url can be retrieved with configuration.Get() - maybe it would be useful to refactor the proxy parsing function to a different package, to avoid an import cycle, but I can do that as well if you are not too proficient with Go.

@voldyman
Copy link
Author

i think i kinda did what you asked, added the http.request to the params structs, didn't need to update any parsing code (it needs codegen that i wasn't sure of anyway).
does this look better?

@voldyman
Copy link
Author

Let me know if you want any other change or if you want to implement it yourself

@Forceu
Copy link
Owner

Forceu commented Feb 14, 2026

Thanks, I will probably modify the PR a bit next week, unfortunately I don't have a lot of time in the coming days.

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