-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
Http.java
2663 lines (2356 loc) · 83.5 KB
/
Http.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2009-2017 Lightbend Inc. <https://www.lightbend.com>
*/
package play.mvc;
import akka.stream.Materializer;
import akka.stream.javadsl.Sink;
import akka.stream.javadsl.Source;
import akka.util.ByteString;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.collect.Lists;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import play.api.http.HttpConfiguration;
import play.api.libs.json.JsValue;
import play.api.mvc.Headers$;
import play.api.mvc.request.*;
import play.core.j.JavaContextComponents;
import play.core.j.JavaHelpers$;
import play.core.j.JavaParsers;
import play.i18n.Lang;
import play.i18n.Langs;
import play.i18n.Messages;
import play.i18n.MessagesApi;
import play.libs.Files;
import play.libs.Json;
import play.libs.Scala;
import play.libs.XML;
import play.libs.typedmap.TypedKey;
import play.libs.typedmap.TypedMap;
import play.mvc.Http.Cookie.SameSite;
import scala.collection.immutable.Map$;
import scala.compat.java8.OptionConverters;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import java.security.cert.X509Certificate;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
/**
* Defines HTTP standard objects.
*/
public class Http {
/**
* The global HTTP context.
*/
public static class Context {
public static ThreadLocal<Context> current = new ThreadLocal<>();
/**
* Retrieves the current HTTP context, for the current thread.
*
* @return the context
*/
public static Context current() {
Context c = current.get();
if(c == null) {
throw new RuntimeException("There is no HTTP Context available from here.");
}
return c;
}
//
private final Long id;
private final play.api.mvc.RequestHeader header;
private final Request request;
private final Response response;
private final Session session;
private final Flash flash;
private final JavaContextComponents components;
private Lang lang = null;
/**
* Creates a new HTTP context.
*
* @param requestBuilder the HTTP request builder.
* @param components the context components.
*/
public Context(RequestBuilder requestBuilder, JavaContextComponents components) {
this(requestBuilder.build(), components);
}
/**
* Creates a new HTTP context.
*
* @param request the HTTP request
* @param components the context components.
*/
public Context(Request request, JavaContextComponents components) {
this.request = request;
this.header = request.asScala();
this.id = header.id();
this.response = new Response();
this.session = new Session(Scala.asJava(header.session().data()));
this.flash = new Flash(Scala.asJava(header.flash().data()));
this.args = new HashMap<>();
this.args.putAll(Scala.asJava(header.tags()));
this.components = components;
}
/**
* Creates a new HTTP context.
*
* @param id the unique context ID
* @param header the request header
* @param request the request with body
* @param sessionData the session data extracted from the session cookie
* @param flashData the flash data extracted from the flash cookie
* @param args any arbitrary data to associate with this request context.
* @param components the context components.
*/
public Context(Long id, play.api.mvc.RequestHeader header, Request request,
Map<String,String> sessionData, Map<String,String> flashData, Map<String,Object> args,
JavaContextComponents components) {
this(id, header, request, new Response(), new Session(sessionData), new Flash(flashData),
new HashMap<>(args), components);
}
/**
* Creates a new HTTP context, using the references provided.
*
* Use this constructor (or withRequest) to copy a context within a Java Action to be passed to a delegate.
*
* @param id the unique context ID
* @param header the request header
* @param request the request with body
* @param response the response instance to use
* @param session the session instance to use
* @param flash the flash instance to use
* @param args any arbitrary data to associate with this request context.
* @param components the context components.
*/
public Context(Long id, play.api.mvc.RequestHeader header, Request request, Response response,
Session session, Flash flash, Map<String,Object> args, JavaContextComponents components) {
this.id = id;
this.header = header;
this.request = request;
this.response = response;
this.session = session;
this.flash = flash;
this.args = args;
this.components = components;
}
/**
* The context id (unique)
*
* @return the id
*/
public Long id() {
return id;
}
/**
* Returns the current request.
*
* @return the request
*/
public Request request() {
return request;
}
/**
* Returns the current response.
*
* @return the response
*/
public Response response() {
return response;
}
/**
* Returns the current session.
*
* @return the session
*/
public Session session() {
return session;
}
/**
* Returns the current flash scope.
*
* @return the flash scope
*/
public Flash flash() {
return flash;
}
/**
* The original Play request Header used to create this context.
* For internal usage only.
*
* @return the original request header.
*/
public play.api.mvc.RequestHeader _requestHeader() {
return header;
}
/**
* The current lang
*
* @return the current lang
*/
public Lang lang() {
if (lang != null) {
return lang;
} else {
return messages().lang();
}
}
/**
* @return the messages for the current lang
*/
public Messages messages() {
Cookie langCookie = request().cookies().get(messagesApi().langCookieName());
Lang cookieLang = langCookie == null ? null : new Lang(play.api.i18n.Lang.apply(langCookie.value()));
LinkedList<Lang> langs = Lists.newLinkedList(request().acceptLanguages());
if (cookieLang != null) {
langs.addFirst(cookieLang);
}
if (lang != null) {
langs.addFirst(lang);
}
return messagesApi().preferred(langs);
}
/**
* Change durably the lang for the current user.
*
* @param code New lang code to use (e.g. "fr", "en-US", etc.)
* @return true if the requested lang was supported by the application, otherwise false
*/
public boolean changeLang(String code) {
return changeLang(Lang.forCode(code));
}
/**
* Change durably the lang for the current user.
*
* @param lang New Lang object to use
* @return true if the requested lang was supported by the application, otherwise false
*/
public boolean changeLang(Lang lang) {
if (langs().availables().contains(lang)) {
this.lang = lang;
scala.Option<String> domain = sessionDomain();
Cookie langCookie = new Cookie(messagesApi().langCookieName(),
lang.code(),
null,
sessionPath(),
domain.isDefined() ? domain.get() : null,
messagesApi().langCookieSecure(),
messagesApi().langCookieHttpOnly(),
SameSite.LAX
);
response.setCookie(langCookie);
return true;
} else {
return false;
}
}
/**
* Clear the lang for the current user.
*/
public void clearLang() {
this.lang = null;
scala.Option<String> domain = sessionDomain();
response.discardCookie(messagesApi().langCookieName(), sessionPath(),
domain.isDefined() ? domain.get() : null, messagesApi().langCookieSecure());
}
private Langs langs() {
return components.langs();
}
private MessagesApi messagesApi() {
return components.messagesApi();
}
private scala.Option<String> sessionDomain() {
return components.httpConfiguration().session().domain();
}
private String sessionPath() {
return components.httpConfiguration().context();
}
/**
* Set the language for the current request, but don't
* change the language cookie. This means the language
* will be set for this request, but will not change for
* future requests.
*
* @param code the language code to set (e.g. "en-US")
* @throws IllegalArgumentException If the given language
* is not supported by the application.
*/
public void setTransientLang(String code) {
setTransientLang(Lang.forCode(code));
}
/**
* Set the language for the current request, but don't
* change the language cookie. This means the language
* will be set for this request, but will not change for
* future requests.
*
* @param lang the language to set
* @throws IllegalArgumentException If the given language
* is not supported by the application.
*/
public void setTransientLang(Lang lang) {
final Langs langs = components.langs();
if (langs.availables().contains(lang)) {
this.lang = lang;
} else {
throw new IllegalArgumentException("Language not supported in this application: " + lang + " not in " + langs.availables());
}
}
/**
* Clear the language for the current request, but don't
* change the language cookie. This means the language
* will be cleared for this request (so a default will be
* used), but will not change for future requests.
*/
public void clearTransientLang() {
this.lang = null;
}
/**
* Free space to store your request specific data.
*/
public Map<String, Object> args;
public FileMimeTypes fileMimeTypes() {
return components.fileMimeTypes();
}
/**
* Import in templates to get implicit HTTP context.
*/
public static class Implicit {
/**
* Returns the current response.
*
* @return the current response.
*/
public static Response response() {
return Context.current().response();
}
/**
* Returns the current request.
*
* @return the current request.
*/
public static Request request() {
return Context.current().request();
}
/**
* Returns the current flash scope.
*
* @return the current flash scope.
*/
public static Flash flash() {
return Context.current().flash();
}
/**
* Returns the current session.
*
* @return the current session.
*/
public static Session session() {
return Context.current().session();
}
/**
* Returns the current lang.
*
* @return the current lang.
*/
public static Lang lang() {
return Context.current().lang();
}
/**
* @return the messages for the current lang
*/
public static Messages messages() {
return Context.current().messages();
}
/**
* Returns the current context.
*
* @return the current context.
*/
public static Context ctx() {
return Context.current();
}
}
/**
* @return a String representation
*/
public String toString() {
return "Context attached to (" + request() + ")";
}
/**
* Create a new context with the given request.
*
* The id, Scala RequestHeader, session, flash and args remain unchanged.
*
* This method is intended for use within a Java action, to create a new Context to pass to a delegate action.
*
* @param request The request to create the new header from.
* @return The new context.
*/
public Context withRequest(Request request) {
return new Context(id, header, request, response, session, flash, args, components);
}
}
/**
* A wrapped context.
* Use this to modify the context in some way.
*/
public static abstract class WrappedContext extends Context {
private final Context wrapped;
/**
* @param wrapped the context the created instance will wrap
*/
public WrappedContext(Context wrapped) {
super(wrapped.id(), wrapped._requestHeader(), wrapped.request(), wrapped.session(), wrapped.flash(), wrapped.args, wrapped.components);
this.args = wrapped.args;
this.wrapped = wrapped;
}
@Override
public Long id() {
return wrapped.id();
}
@Override
public Request request() {
return wrapped.request();
}
@Override
public Response response() {
return wrapped.response();
}
@Override
public Session session() {
return wrapped.session();
}
@Override
public Flash flash() {
return wrapped.flash();
}
@Override
public play.api.mvc.RequestHeader _requestHeader() {
return wrapped._requestHeader();
}
@Override
public Lang lang() {
return wrapped.lang();
}
@Override
public boolean changeLang(String code) {
return wrapped.changeLang(code);
}
@Override
public boolean changeLang(Lang lang) {
return wrapped.changeLang(lang);
}
@Override
public void clearLang() {
wrapped.clearLang();
}
}
public static class Headers {
private final Map<String, List<String>> headers;
public Headers(Map<String, List<String>> headers) {
this.headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
this.headers.putAll(headers);
}
/**
* @return all the headers as a map.
*/
public Map<String, List<String>> toMap() {
return headers;
}
/**
* Checks if the given header is present.
*
* @param headerName The name of the header (case-insensitive)
* @return <code>true</code> if the request did contain the header.
*/
public boolean contains(String headerName) {
return headers.containsKey(headerName);
}
/**
* Gets the header value. If more than one value is associated with this header, then returns the first one.
*
* @param name the header name
* @return the first header value or empty if no value available.
*/
public Optional<String> get(String name) {
return Optional.ofNullable(headers.get(name)).flatMap(headerValues -> headerValues.stream().findFirst());
}
/**
* Get all the values associated with the header name.
*
* @param name the header name.
* @return the list of values associates with the header of empty.
*/
public List<String> getAll(String name) {
return headers.getOrDefault(name, Collections.emptyList());
}
/**
* @return the scala version of this headers.
*/
public play.api.mvc.Headers asScala() {
return new play.api.mvc.Headers(JavaHelpers$.MODULE$.javaMapOfListToScalaSeqOfPairs(this.headers));
}
/**
* Add a new header with the given value.
*
* @param name the header name
* @param value the header value
* @return this with the new header added
*/
public Headers addHeader(String name, String value) {
this.headers.put(name, Collections.singletonList(value));
return this;
}
/**
* Add a new header with the given values.
*
* @param name the header name
* @param values the header values
* @return this with the new header added
*/
public Headers addHeader(String name, List<String> values) {
this.headers.put(name, values);
return this;
}
/**
* Remove a header.
*
* @param name the header name.
* @return this without the removed header.
*/
public Headers remove(String name) {
this.headers.remove(name);
return this;
}
}
public interface RequestHeader {
/**
* The complete request URI, containing both path and query string.
*
* @return the uri
*/
String uri();
/**
* The HTTP Method.
*
* @return the http method
*/
String method();
/**
* The HTTP version.
*
* @return the version
*/
String version();
/**
* The client IP address.
*
* retrieves the last untrusted proxy
* from the Forwarded-Headers or the X-Forwarded-*-Headers.
*
* @return the remote address
*/
String remoteAddress();
/**
* Is the client using SSL?
*
* @return true that the client is using SSL
*/
boolean secure();
/**
* @return a map of typed attributes associated with the request.
*/
TypedMap attrs();
/**
* Create a new version of this object with the given attributes attached to it.
*
* @param newAttrs The new attributes to add.
* @return The new version of this object with the attributes attached.
*/
RequestHeader withAttrs(TypedMap newAttrs);
/**
* Create a new versions of this object with the given attribute attached to it.
*
* @param key The new attribute key.
* @param value The attribute value.
* @param <A> the attribute type
* @return The new version of this object with the new attribute.
*/
<A> RequestHeader addAttr(TypedKey<A> key, A value);
/**
* Attach a body to this header.
*
* @param body The body to attach.
* @return A new request with the body attached to the header.
*/
Request withBody(RequestBody body);
/**
* The request host.
*
* @return the host
*/
String host();
/**
* The URI path.
*
* @return the path
*/
String path();
/**
* The Request Langs extracted from the Accept-Language header and sorted by preference (preferred first).
*
* @return the preference-ordered list of languages accepted by the client
*/
List<play.i18n.Lang> acceptLanguages();
/**
* @return The media types set in the request Accept header, sorted by preference (preferred first)
*/
List<play.api.http.MediaRange> acceptedTypes();
/**
* Check if this request accepts a given media type.
*
* @param mimeType the mimeType to check for support.
* @return true if <code>mimeType</code> is in the Accept header, otherwise false
*/
boolean accepts(String mimeType);
/**
* The query string content.
*
* @return the query string map
*/
Map<String,String[]> queryString();
/**
* Helper method to access a queryString parameter.
*
* @param key the query string parameter to look up
* @return the value for the provided <code>key</code>.
*/
String getQueryString(String key);
/**
* @return the request cookies
*/
Cookies cookies();
/**
* @param name Name of the cookie to retrieve
* @return the cookie, if found, otherwise null
*/
Cookie cookie(String name);
/**
* Retrieve all headers.
*
* @return the request headers for this request.
*/
Headers getHeaders();
/**
* Retrieves all headers.
*
* @return a map of of header name to headers with case-insensitive keys
*
* @deprecated Deprecated as of 2.6.0. Use {@link #getHeaders()} instead.
*/
@Deprecated
default Map<String,String[]> headers() {
final Map<String, String[]> result = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
this.getHeaders().headers.forEach((key, values) -> {
String[] valuesArray = new String[values.size()];
result.put(key, values.toArray(valuesArray));
});
return result;
}
/**
* Retrieves a single header.
*
* @param headerName The name of the header (case-insensitive)
* @return the value corresponding to <code>headerName</code>, or null if it was not present
*
* @deprecated Deprecated as of 2.6.0. Use {@link #header(String)} ()} instead.
*/
@Deprecated
default String getHeader(String headerName) {
return getHeaders().get(headerName).orElse(null);
}
/**
* Retrieves a single header.
*
* @param headerName The name of the header (case-insensitive)
* @return the value corresponding to <code>headerName</code>, or empty if it was not present
*/
default Optional<String> header(String headerName) {
return getHeaders().get(headerName);
}
/**
* Checks if the request has the header.
*
* @param headerName The name of the header (case-insensitive)
* @return <code>true</code> if the request did contain the header.
*/
default boolean hasHeader(String headerName) {
return getHeaders().contains(headerName);
}
/**
* Checks if the request has a body.
*
* @return true if request has a body, false otherwise.
*/
boolean hasBody();
/**
* Get the content type of the request.
*
* @return The request content type excluding the charset, if it exists.
*/
Optional<String> contentType();
/**
* Get the charset of the request.
*
* @return The request charset, which comes from the content type header, if it exists.
*/
Optional<String> charset();
/**
* The X509 certificate chain presented by a client during SSL requests.
*
* @return The chain of X509Certificates used for the request if the request is secure and the server supports it.
*/
Optional<List<X509Certificate>> clientCertificateChain();
/**
* @return the tags for the request
* @deprecated Use <code>attr</code>, <code>withAttr</code>, etc.
*/
@Deprecated
Map<String, String> tags();
/**
* For internal Play-use only
*
* @return the underlying request
* @deprecated As of release 2.6.0. Use {@link #asScala()}
*/
@Deprecated
play.api.mvc.RequestHeader _underlyingHeader();
/**
* Return the Scala version of the request header.
*
* @return the Scala version for this request header.
* @see play.api.mvc.RequestHeader
*/
play.api.mvc.RequestHeader asScala();
}
/**
* An HTTP request.
*/
public interface Request extends RequestHeader {
/**
* The request body.
*
* @return the body
*/
RequestBody body();
Request withBody(RequestBody body);
// Override return type
Request withAttrs(TypedMap newAttrs);
// Override return type
<A> Request addAttr(TypedKey<A> key, A value);
/**
* The user name for this request, if defined.
* This is usually set by annotating your Action with <code>@Authenticated</code>.
*
* @return the username
* @deprecated As of release 2.6, use <code>attrs.get(Security.USERNAME)</code> or <code>attrs.getOptional(Security.USERNAME)</code>.
*/
@Deprecated String username();
/**
* Returns a request updated with specified user name
*
* @param username the new user name
* @return a copy of the request containing the specified user name
* @deprecated As of release 2.6, use <code>req.withAttrs(req.attrs().put(Security.USERNAME, username))</code>.
*/
@Deprecated Request withUsername(String username);
/**
* For internal Play-use only
*
* @return the underlying request
* @deprecated As of release 2.6.0. Use {@link #asScala()}
*/
@Deprecated
play.api.mvc.Request<RequestBody> _underlyingRequest();
/**
* Return the Scala version of the request
*
* @return the underlying request.
* @see play.api.mvc.Request
*/
play.api.mvc.Request<RequestBody> asScala();
}
/**
* An HTTP request.
*/
public static class RequestImpl extends play.core.j.RequestImpl {
/**
* Constructor only based on a header.
* @param header the header from a request
*/
public RequestImpl(play.api.mvc.RequestHeader header) {
super(header.withBody(null));
}
/**
* Constructor with a requestbody.
* @param request the body of the request
*/
public RequestImpl(play.api.mvc.Request<RequestBody> request) {
super(request);
}
}
/**
* The builder for building a request.
*/
public static class RequestBuilder {
protected play.api.mvc.Request<RequestBody> req;
/**
* Returns a simple request builder. The initial request is "GET / HTTP/1.1" from
* 127.0.0.1 over an insecure connection. The request is created using the default
* factory.
*/
public RequestBuilder() {
this(new DefaultRequestFactory(HttpConfiguration.createWithDefaults()));
// Add a host of "localhost" to validate against the AllowedHostsFilter.
this.host("localhost");
}
/**
* Returns a simple request builder. The initial request is "GET / HTTP/1.1" from
* 127.0.0.1 over an insecure connection. The request is created using the given
* factory.
* @param requestFactory the incoming request factory
*/
public RequestBuilder(RequestFactory requestFactory) {
req = requestFactory.createRequest(
RemoteConnection$.MODULE$.apply("127.0.0.1", false, OptionConverters.toScala(Optional.empty())),
"GET",
RequestTarget$.MODULE$.apply("/", "/", Map$.MODULE$.empty()),
"HTTP/1.1",
Headers$.MODULE$.create(),
TypedMap.empty().underlying(),
new RequestBody(null)
);
}
/**
* @return the request body, if a previously the body has been set
*/
public RequestBody body() {
return req.body();
}
/**
* Get the username. This method calls <code>attrs().getOptional(Security.USERNAME)</code>.
* @return the username or null
* @deprecated Use <code>attrs().get(Security.USERNAME)</code> or <code>attrs().getOptional(Security.USERNAME)</code> instead.
*/
@Deprecated
public String username() {
return attrs().getOptional(Security.USERNAME).orElse(null);
}
/**
* Set the username. This method calls <code>attr(Security.USERNAME, username)</code>.
* @param username the username for the request
* @return the modified builder
* @deprecated Use <code>attr(Security.USERNAME, username)</code> instead.
*/
@Deprecated
public RequestBuilder username(String username) {
attr(Security.USERNAME, username);
return this;
}
/**
* Set the body of the request.
*
* @param body the body
* @param contentType Content-Type header value
* @return the modified builder
*/
protected RequestBuilder body(RequestBody body, String contentType) {
header("Content-Type", contentType);
body(body);
return this;
}
/**
* Set the body of the request.
*