Added Webclient, refactored Webserver to share streamed body sending and receiving logic.#2771
Added Webclient, refactored Webserver to share streamed body sending and receiving logic.#2771jurgenvinju wants to merge 69 commits into
Conversation
…he same Response and Request encodings
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2771 +/- ##
========================================
- Coverage 46% 46% -1%
+ Complexity 6718 6714 -4
========================================
Files 794 795 +1
Lines 65937 66220 +283
Branches 9889 9918 +29
========================================
+ Hits 30760 30761 +1
- Misses 32797 33079 +282
Partials 2380 2380 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
DavyLandman
left a comment
There was a problem hiding this comment.
I think this is a nice idea but not ready yet, I've written down my concerns.
I think this needs tests.
|
Great review @DavyLandman I'll try and improve this PR and let's have a look together later again. I've tested this client so far with a couple of web APIs and some very large test downloads. It seems very natural apart from the host/path/query separation. I think some shorthands where a full URL can be used which is split up internally would be nice. Also there is no support for fragments yet. |
… body in a POST and PUT ina Request, the same way as on the Response side. So support for text, json and file content. HTML is for later.
…nd receive, and also enabled all body kinds for the server side now, also with POST and PUT requests. This also introduces streaming to the JSON and string responses, and post/put requests are also streamed now.
…is missing. Also added query parameters to the client.
|
| } | ||
| catch (InvocationTargetException e) { | ||
| throw new JavaMethodLink(className, e.getMessage(), e); | ||
| String cause = e.getTargetException().getMessage(); |
There was a problem hiding this comment.
this is superfluous now
| private IFunction formatters; | ||
| private boolean explicitConstructorNames = false; | ||
| private boolean explicitDataTypes; | ||
| private boolean fileLocationsAsPathOnly = true; |
There was a problem hiding this comment.
check why this is gone
| return this; | ||
| } | ||
|
|
||
| public JsonValueWriter setFileLocationsAsPathOnly(boolean setting) { |
| this.tf = tf; | ||
| this.vf = vf; | ||
| this.monitor = monitor; | ||
| this.html = null; // initialize later from reified type |
There was a problem hiding this comment.
this can be done eagerly, now that we cut off the dependency on TypeStore instances from the ModuleEnvironments.
| */ | ||
| public IFunction createBodyReceiver(InputStream input, ISourceLocation url, String contentType, String charset) { | ||
| TypeStore store = new TypeStore(); | ||
| var BodyKind = tf.abstractDataType(store, "BodyKind"); |
There was a problem hiding this comment.
move these to final fields
|
|
||
| IConstructor options = kind.asWithKeywordParameters().getParameter("jOptions"); | ||
|
|
||
| try { |
There was a problem hiding this comment.
check if these streams need closing. that was not allowed in the NanoHTTP times, but things may be different now with Undertow.
| } | ||
| } | ||
|
|
||
| // exchange.endExchange(); |
There was a problem hiding this comment.
check if we need this
| } | ||
|
|
||
| private String getMimeType(HeaderMap headers) { | ||
| String contenType = headers.getFirst(Headers.CONTENT_TYPE); |
| if (parts.length > 1) { | ||
| String[] assign = parts[1].split("="); | ||
|
|
||
| if (assign[0].equals("charset")) { |
|
|
||
| private IMap makeMap(Map<String, Deque<String>> headers) { | ||
| IMapWriter writer = vf.mapWriter(); | ||
| for (Entry<String, Deque<String>> entry : headers.entrySet()) { |
There was a problem hiding this comment.
what about the other elements in the Deque?
| Response response(Status status, str mimeType, map[str, str] headers, Body body) | ||
| = response(status, body[mimeType=mimeType], headers=headers); | ||
|
|
||
| @synopsis{Bodies can be sent or received, depending on the context (client or)} |
| } | ||
| } | ||
| else { | ||
| else if (!kwFormals.isBottom()) { |
There was a problem hiding this comment.
this is an unrelated fix that was annoying during testing of the client and server.
|
|
||
| public static String yield(IConstructor tree, int limit) { | ||
| return yield(tree, false, limit); | ||
| return TreeAdapter.yield(tree, false, limit); |



Response fetch(Request)RequestandResponsedata-typesendandreceivekind:sendis used for serverresponseand clientputandgetreceiveis used for serverputandgetand clientresponseUnfortunately Undertow requires at least a Java 17 JVM.