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

hs.http must follow redirects #1889 #3279

Merged
merged 1 commit into from
Nov 2, 2022
Merged

Conversation

pdckxd
Copy link
Contributor

@pdckxd pdckxd commented Aug 22, 2022

  1. new parameter "enableRedirect" for hs.http.doAsyncRequest
  2. add 5 tests to test this change

extensions/http/test_http.lua Outdated Show resolved Hide resolved
extensions/http/test_http.lua Outdated Show resolved Hide resolved
extensions/http/test_http.lua Outdated Show resolved Hide resolved
extensions/http/test_http.lua Outdated Show resolved Hide resolved
extensions/http/test_http.lua Outdated Show resolved Hide resolved
extensions/http/test_http.lua Outdated Show resolved Hide resolved
extensions/http/test_http.lua Outdated Show resolved Hide resolved
extensions/http/test_http.lua Outdated Show resolved Hide resolved
extensions/http/test_http.lua Outdated Show resolved Hide resolved
extensions/http/test_http.lua Outdated Show resolved Hide resolved
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

This pull request does not contain a valid label. Please add one of the following labels: pr-fix, pr-change, pr-feature, pr-maintenance

@pdckxd pdckxd force-pushed the master branch 3 times, most recently from 0e7a1e5 to 8cd292e Compare August 22, 2022 03:09

NSString* cachePolicy = nil;
if (lua_type(L, 6) == LUA_TSTRING) {
cachePolicy = [skin toNSObjectAtIndex:6];
}

bool enableRedirect = true;
if (lua_type(L, 7) == LUA_TBOOLEAN) {
Copy link
Member

Choose a reason for hiding this comment

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

The way you have this now, to specify the enableRedirect option, the cachePolicy becomes non-optional. We are very inconsistent about this sort of thing across the codebase, but FWIW it's pretty easy to handle - add LS_TBOOLEAN as an option for the 6th argument and here check the lua_type() of position 6 first, to see if the boolean is there.
This scales very poorly with lots of additional optional arguments, but for the first one it's not too bad.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make sense. Let me revise. Thanks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apart from optional string & boolean, I am thinking about if we can also support optional table for 6th parameter. Users can pass {cachePolicy= "xxx", enableRedirect=false} if they want to use both 2 parameters. What's your opinion? @cmsj

@cmsj cmsj added the pr-feature Pull Request implementing a feature label Aug 22, 2022
@github-actions
Copy link

View Test Results

349 tests   296 ✔️  1h 3m 4s ⏱️
    2 suites    52 💤
    1 files        1

For more details on these failures, see this check.

Results for commit 8cd292e.

1. new optional parameter "enableRedirect" for hs.http.doAsyncRequest
2. add 4 tests to test this change

pr-feature
@cmsj
Copy link
Member

cmsj commented Nov 2, 2022

The optional table idea is what we should have done, but for now we're stuck with the idioms we have.
Apologies for taking a long time to get back to this. I'll merge it now and I have a small tweak to apply on top of it, in #3311

@cmsj cmsj merged commit 2ccf9ca into Hammerspoon:master Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-feature Pull Request implementing a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants