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

Add support for disabling redirects #28

Merged
merged 5 commits into from
Sep 7, 2023

Conversation

WinterPhoenix
Copy link
Contributor

@WinterPhoenix WinterPhoenix commented Sep 2, 2023

I have a use case where what I need the HTTP call to do is "expand" the URL. Basically do the opposite of what a link-shortening service does, where we want the Location header. Normally in cURL, this would be controlled by CURLOPT_FOLLOWLOCATION, but I didn't want to fiddle with your existing implementation too much.

What I've added is a per-HTTPRequest boolean called noredirect. It's false by default (follow redirects).

Also for some reason I can't get the new tests to work, but the changes do work on a real GMod server, at least with linux64. I'm probably just missing something. If I figure that out, I'll update the PR.

@timschumi
Copy link
Owner

I have a use case where what I need the HTTP call to do is "expand" the URL. Basically do the opposite of what a link-shortening service does, where we want the Location header.

I don't mind putting this in (there are worse things to feature creep on), but I'm unsure if just writing something custom using gmcurl might be a better fit. Granted, I'll most likely have to add some functionality to that instead then, but I'm very happy to do that.

Normally in cURL, this would be controlled by CURLOPT_FOLLOWLOCATION, but I didn't want to fiddle with your existing implementation too much.

The reason why we aren't using CURLOPT_FOLLOWLOCATION here (we did ages ago) is because we need to clear our saved response data when following along. Your implementation for noredirect looks fine.

Also for some reason I can't get the new tests to work, but the changes do work on a real GMod server, at least with linux64. I'm probably just missing something. If I figure that out, I'll update the PR.

You put noredirect into the test case struct instead of the HTTPRequest struct by accident. :^)

@WinterPhoenix
Copy link
Contributor Author

I don't mind putting this in (there are worse things to feature creep on), but I'm unsure if just writing something custom using gmcurl might be a better fit. Granted, I'll most likely have to add some functionality to that instead then, but I'm very happy to do that.

I prefer the simplicity of a mostly-drop-in replacement to be honest.

You put noredirect into the test case struct instead of the HTTPRequest struct by accident. :^)

Oh, lol. Fixed it...after some wrangling with the Location header in the test. For some reason it's is populated with the full URL in the test, but not on a real GMod SRCDS server.

Copy link
Owner

@timschumi timschumi left a comment

Choose a reason for hiding this comment

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

LGTM! The full URL mixup is probably not an actual issue, or at least not one that we are at fault for. It's more likely that flask is trying to be too smart for its own good.

@timschumi timschumi merged commit 2bc85cb into timschumi:master Sep 7, 2023
3 checks passed
@timschumi
Copy link
Owner

Released in version 1.9.0.

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.

None yet

2 participants