Skip to content

Commit c012ee1

Browse files
Pass request form values and cookies to an NGRequest constructor
1 parent 89e246d commit c012ee1

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

ng-adaptor-jetty/src/main/java/ng/adaptor/jetty/NGAdaptorJetty.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,14 @@ public InvocationType getInvocationType() {
288288
}
289289
} );
290290

291-
final NGRequest request = new NGRequest( jettyRequest.getMethod(), jettyRequest.getHttpURI().getCanonicalPath(), "FIXME", headerMap( jettyRequest ), new byte[] {} ); // FIXME: It makes little sense to set the request content to be empty here... // Hugi 2025-04-05
292-
request._setFormValues( formValues );
293-
request._setCookieValues( cookieValues( Request.getCookies( jettyRequest ) ) );
291+
final String method = jettyRequest.getMethod();
292+
final String uri = jettyRequest.getHttpURI().getCanonicalPath();
293+
final String httpVersion = jettyRequest.getConnectionMetaData().getHttpVersion().asString();
294+
final Map<String, List<String>> headers = headerMap( jettyRequest );
295+
final Map<String, List<String>> cookieValues = cookieValues( Request.getCookies( jettyRequest ) );
296+
final byte[] content = new byte[] {}; // FIXME: This just kind of reflects the badness of our request data model. The request's "content" is really the part list ... // Hugi 2025-04-05
297+
298+
final NGRequest request = new NGRequest( method, uri, httpVersion, headers, formValues, cookieValues, content );
294299
uploadedFiles.entrySet().forEach( p -> request._uploadedFiles().put( p.getKey(), p.getValue() ) ); // FIXME: Adding uploaded files this way is really, really temporary // Hugi 2025-04-05
295300
return request;
296301
}
@@ -305,6 +310,7 @@ private static NGRequest requestToNGRequest( final Request jettyRequest ) {
305310

306311
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
307312

313+
// FIXME: we're always consuming the request's entire body at this point. Allowing us to pass in a stream would be... sensible // Hugi 2025-06-09
308314
try( final InputStream is = Request.asInputStream( jettyRequest )) {
309315
is.transferTo( bos );
310316
}
@@ -316,17 +322,10 @@ private static NGRequest requestToNGRequest( final Request jettyRequest ) {
316322
final String uri = jettyRequest.getHttpURI().getCanonicalPath();
317323
final String httpVersion = jettyRequest.getConnectionMetaData().getHttpVersion().asString();
318324
final Map<String, List<String>> headers = headerMap( jettyRequest );
325+
final Map<String, List<String>> cookieValues = cookieValues( Request.getCookies( jettyRequest ) );
319326
final byte[] content = bos.toByteArray();
320327

321-
final NGRequest request = new NGRequest( method, uri, httpVersion, headers, content );
322-
323-
// FIXME: Form value parsing should really happen within the request object, not in the adaptor // Hugi 2021-12-31
324-
request._setFormValues( formValues );
325-
326-
// FIXME: Cookie parsing should happen within the request object, not in the adaptor // Hugi 2021-12-31
327-
request._setCookieValues( cookieValues( Request.getCookies( jettyRequest ) ) );
328-
329-
return request;
328+
return new NGRequest( method, uri, httpVersion, headers, formValues, cookieValues, content );
330329
}
331330

332331
/**

ng-appserver/src/main/java/ng/appserver/NGRequest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public class NGRequest extends NGMessage {
6060
*/
6161
private NGSession _session;
6262

63-
public NGRequest( final String method, final String uri, final String httpVersion, final Map<String, List<String>> headers, final byte[] contentBytes ) {
63+
public NGRequest( final String method, final String uri, final String httpVersion, final Map<String, List<String>> headers, final Map<String, List<String>> formValues, final Map<String, List<String>> cookieValues, final byte[] contentBytes ) {
6464
Objects.requireNonNull( method );
6565
Objects.requireNonNull( uri );
6666
Objects.requireNonNull( httpVersion );
@@ -71,9 +71,19 @@ public NGRequest( final String method, final String uri, final String httpVersio
7171
setURI( uri );
7272
setHttpVersion( httpVersion );
7373
setHeaders( headers );
74+
_setFormValues( formValues );
75+
_setCookieValues( cookieValues );
7476
setContentBytes( contentBytes );
7577
}
7678

79+
/**
80+
* FIXME: Old constructor that doesn't set formValues and cookieValues. It's role is a little unclear at the moment, since I'm still considering if having parsing of form values/cookie values in NGRequest makes sense // Hugi 2025-06-09
81+
*/
82+
@Deprecated
83+
public NGRequest( final String method, final String uri, final String httpVersion, final Map<String, List<String>> headers, final byte[] contentBytes ) {
84+
this( method, uri, httpVersion, headers, null, null, contentBytes );
85+
}
86+
7787
/**
7888
* @return The requests form values (query parameters)
7989
*/

0 commit comments

Comments
 (0)