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

HTTP.request function upgrade! #515

Open
wants to merge 15 commits into
base: master
from

Conversation

Projects
None yet
3 participants
@JasonTheKitten
Copy link

JasonTheKitten commented Feb 1, 2018

I think that this time it will pass the travis-ci
Edit: Yay, it did. Time before this it did not

Added important HTTP features used by many real-world applications!
Compatibility is retained with 99.9% of programs!
Interact with servers that require non-get/post methods!

Updates include getting the text that goes with the response code from the server instead of using a lookup table that may not match the server's, the ability to use methods other than post and get, and also the ability to enable or disable automatic page redirects.

I thought about adding a way to get the encryption certificate, but decided against it.
Also, due to limitations of httpurlconnections, there is a whitelist of usable methods. This can probably be changed by writing a script to communicate directly with a socket, but under the same name and with the same methods (so we don't have to change all of our other code), but I decided to let whoever else do that, or maybe I'll do that later, but right now I'm not too worried about it.

JasonTheKitten added some commits Jan 25, 2018

@Override
public void shutdown( )

This comment has been minimized.

@SquidDev

SquidDev Feb 1, 2018

Contributor

I don't like to nitpick, but it's probably best to keep whitespace changes to a minimum. I know indent styles are rather a personal matter, but it's best to be consistent :). It also makes it easier to review the PR and see what functionality has changed, rather than what's just cosmetic.

This comment has been minimized.

@JasonTheKitten

JasonTheKitten Feb 1, 2018

Author

BTW, it really annoys me that the {'s seem to be on a separate line than the code controlling the block, but I try to follow that formatting anyways. Don't know why.

This comment has been minimized.

@SquidDev

SquidDev Feb 1, 2018

Contributor

Yeah, there's lots of things I'm not a fan of as far as CC's formatting goes, but you have to roll with it :).

}

//Get mode
String DMODE = "GET";

This comment has been minimized.

@SquidDev

SquidDev Feb 1, 2018

Contributor

Also minor stylistic choice, but probably shouldn't be UPPER_CASE - that's normally reserved for constants.

@@ -48,37 +48,47 @@ public static URL checkURL( String urlString ) throws HTTPRequestException
return url;
}

public HTTPRequest( String url, final String postText, final Map<String, String> headers, boolean binary ) throws HTTPRequestException

This comment has been minimized.

@SquidDev

SquidDev Feb 1, 2018

Contributor

This whole file shouldn't exist - I'm pretty sure it's me mucking up a rebase at some point. It's probably best to not edit it at all and someone can delete it in the future (or just delete it now).

This comment has been minimized.

@JasonTheKitten

JasonTheKitten Feb 1, 2018

Author

Thing doesn't seem to work without it though...

This comment has been minimized.

@SquidDev

SquidDev Feb 1, 2018

Contributor

Strange. From what I can tell, all references are pointing towards apis.http.HTTPRequest instead of apis.HTTPRequest. What error do you get?

This comment has been minimized.

@JasonTheKitten

JasonTheKitten Feb 2, 2018

Author

I might be wrong, I'll have to check

This comment has been minimized.

@JasonTheKitten

JasonTheKitten Feb 2, 2018

Author

Ok, I was wrong. I was thinking of a different file...

case 2:
{
// getResponseCodeText
return new Object[] { responseCodeText };

This comment has been minimized.

@SquidDev

SquidDev Feb 1, 2018

Contributor

Instead of adding a separate method, I wonder if we could just return both in getResponseCode? Might be a slightly cleaner API.

This comment has been minimized.

@JasonTheKitten

JasonTheKitten Feb 1, 2018

Author

Maybe, can I get Lupus's opinion first though?

@SquidDev

This comment has been minimized.

Copy link
Contributor

SquidDev commented Feb 1, 2018

Aside from my above comments it looks good.

As so far as additional methods go, I've been looking into using Netty's HTTP client instead, as it imposes less restrictions (and also drops the need to have separate threads for each request). One'd probably want to wait until #395 has been reviewed, but it might also be worth looking into.

@JasonTheKitten

This comment has been minimized.

Copy link
Author

JasonTheKitten commented Feb 1, 2018

Their never seems to be a reply option to lupus's comments...

Wrong PR?

Branch copy error, I'm worried that deleting it might delete my other branch?

@SquidDev

This comment has been minimized.

Copy link
Contributor

SquidDev commented Feb 1, 2018

Branch copy error, I'm worried that deleting it might delete my other branch?

It shouldn't - if you're rebasing, it'll just delete those commits on this particular branch.

@JasonTheKitten

This comment has been minimized.

Copy link
Author

JasonTheKitten commented Feb 1, 2018

Ok, got rid of that :)

@SquidDev

This comment has been minimized.

Copy link
Contributor

SquidDev commented Apr 4, 2018

Someone added a request similar to this one on the CC:T issue tracker, so I thought I'd have another look at this and raise a few suggestions. One worry I have is that http.request (and other http methods) are ending up like read, with far too many arguments to keep track of.

One possible solution would be to determine if the first argument is a table (falling back to the current system if not) and extract our options from there. This could use a scheme similar to luasocket.http.request:

http.request {
  url = string,
  [method = string,]
  [headers = header-table,]
  [body = string],
  [redirect = boolean,]
  [binary = boolean,]
}

This means we can add as many arguments and options as we like (well, within reason) whilst still keeping calls readable and maintaining backwards compatibility. Obviously this does make argument parsing more complex (though one could create some helpers for table parsing on the Java side), but I think it's worth it.

@SquidDev SquidDev referenced this pull request Apr 4, 2018

Closed

Other HTTP request methods #21

JasonTheKitten added some commits Apr 9, 2018

Change the DMODE to lowercase
Doesn't really matter

@JasonTheKitten JasonTheKitten deleted the JasonTheKitten:master-http branch Apr 10, 2018

@JasonTheKitten JasonTheKitten restored the JasonTheKitten:master-http branch Apr 10, 2018

@JasonTheKitten

This comment has been minimized.

Copy link
Author

JasonTheKitten commented Apr 10, 2018

I had accidentally deleted this branch...

SquidDev added a commit to SquidDev-CC/CC-Tweaked that referenced this pull request May 15, 2018

Allow multiple HTTP request methods
This implements an argument format similar to LuaReqeust, as described
in dan200/ComputerCraft#515. The Lua argument checking code is a little
verbose and repetitive, but I'm not sure how to avoid that - we should
look into improving it in the future.

Closes #21
@thatcraniumguy

This comment has been minimized.

Copy link

thatcraniumguy commented May 23, 2018

Can one of the admins verify this patch?

@SquidDev SquidDev referenced this pull request Jan 10, 2019

Merged

Http rework #98

4 of 6 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.