-
-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathRequestContext.cfc
More file actions
2069 lines (1859 loc) · 61.2 KB
/
RequestContext.cfc
File metadata and controls
2069 lines (1859 loc) · 61.2 KB
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 Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
* www.ortussolutions.com
* ---
* Models a ColdBox request, stores the incoming request collection (FORM/URL/REMOTE) and private request collection.
* It is also used to determine metadata about a request and helps you build RESTFul responses.
*/
component serializable="false" accessors="true" {
/**
* The request context which contains the URL/FORM or any incoming client data
*/
property name="context" type="struct";
/**
* The private request context which contains safe data your application can produce
*/
property name="privateContext" type="struct";
/**
* ColdBox Controller
*/
property name="controller";
/**
* ColdBox System Properties
*/
property name="properties" type="struct";
/**
* The incoming event name detection string
*/
property name="eventName";
/**
* Execution bit determination. Used to determine if the request is executable or not
*/
property name="isNoExecution" type="boolean";
/**
* Registered system layout ref maps
*/
property name="registeredLayouts" type="struct";
/**
* Registered system folder layout ref maps
*/
property name="folderLayouts" type="struct";
/**
* Registered system folder view ref maps
*/
property name="viewLayouts" type="struct";
/**
* Default system layout
*/
property name="defaultLayout";
/**
* Default system view
*/
property name="defaultView";
/**
* SES Base URL used for the request
*/
property name="SESBaseURL";
/**
* The incoming RESTFul routed struct (if any)
*/
property name="routedStruct" type="struct";
/**
* View Rendering Regions that we will track
*/
property name="renderingRegions" type="struct";
/**
* Response headers generated by the ColdBox application NOT the servlet
*/
property name="responseHeaders" type="struct";
/**
* The request's timeout if set via the setRequestTimeout() method.
*/
property
name ="requestTimeout"
type ="numeric"
default="0";
/**
* The last status code
* This is used mostly for mocking and tracking multi-step responses in case repsonses are committed.
* Defaults to 200 (OK)
*/
property
name ="statusCode"
type ="numeric"
default="200";
/**
* The last status text
*
* @REMOVED by Jakarta EE, remove by 8
*/
property
name ="statusText"
type ="string"
default="";
/************************************** STATIC CONSTRUCTS *********************************************/
// HTTP VERB ALIASES
this.METHODS = {
"HEAD" : "HEAD",
"GET" : "GET",
"POST" : "POST",
"PATCH" : "PATCH",
"PUT" : "PUT",
"DELETE" : "DELETE"
};
// HTTP STATUS CODES
this.STATUS = {
"CREATED" : 201,
"ACCEPTED" : 202,
"SUCCESS" : 200,
"NO_CONTENT" : 204,
"RESET" : 205,
"PARTIAL_CONTENT" : 206,
"BAD_REQUEST" : 400,
"NOT_AUTHORIZED" : 403,
"NOT_AUTHENTICATED" : 401,
"NOT_FOUND" : 404,
"NOT_ALLOWED" : 405,
"NOT_ACCEPTABLE" : 406,
"UNPROCESSABLE_ENTITY" : 422,
"TOO_MANY_REQUESTS" : 429,
"EXPECTATION_FAILED" : 417,
"INTERNAL_ERROR" : 500,
"NOT_IMPLEMENTED" : 501
};
// HTTP STATUS TEXTS
// TODO: REMOVE BY 8
this.STATUS_TEXTS = {
"100" : "Continue",
"101" : "Switching Protocols",
"102" : "Processing",
"200" : "OK",
"201" : "Created",
"202" : "Accepted",
"203" : "Non-authoritative Information",
"204" : "No Content",
"205" : "Reset Content",
"206" : "Partial Content",
"207" : "Multi-Status",
"208" : "Already Reported",
"226" : "IM Used",
"300" : "Multiple Choices",
"301" : "Moved Permanently",
"302" : "Found",
"303" : "See Other",
"304" : "Not Modified",
"305" : "Use Proxy",
"307" : "Temporary Redirect",
"308" : "Permanent Redirect",
"400" : "Bad Request",
"401" : "Unauthorized",
"402" : "Payment Required",
"403" : "Forbidden",
"404" : "Not Found",
"405" : "Method Not Allowed",
"406" : "Not Acceptable",
"407" : "Proxy Authentication Required",
"408" : "Request Timeout",
"409" : "Conflict",
"410" : "Gone",
"411" : "Length Required",
"412" : "Precondition Failed",
"413" : "Payload Too Large",
"414" : "Request-URI Too Long",
"415" : "Unsupported Media Type",
"416" : "Requested Range Not Satisfiable",
"417" : "Expectation Failed",
"418" : "I'm a teapot",
"421" : "Misdirected Request",
"422" : "Unprocessable Entity",
"423" : "Locked",
"424" : "Failed Dependency",
"426" : "Upgrade Required",
"428" : "Precondition Required",
"429" : "Too Many Requests",
"431" : "Request Header Fields Too Large",
"444" : "Connection Closed Without Response",
"451" : "Unavailable For Legal Reasons",
"499" : "Client Closed Request",
"500" : "Internal Server Error",
"501" : "Not Implemented",
"502" : "Bad Gateway",
"503" : "Service Unavailable",
"504" : "Gateway Timeout",
"505" : "HTTP Version Not Supported",
"506" : "Variant Also Negotiates",
"507" : "Insufficient Storage",
"508" : "Loop Detected",
"510" : "Not Extended",
"511" : "Network Authentication Required",
"599" : "Network Connect Timeout Error"
};
// Family Marker
this.cbRequestContext = true;
/************************************** CONSTRUCTOR *********************************************/
/**
* Constructor
*
* @properties The ColdBox application settings
* @controller Acess to the system controller
*/
function init( required struct properties = {}, required any controller ){
// Store controller;
variables.controller = arguments.controller;
// Create the Collections
variables.context = structNew();
variables.privateContext = structNew();
// flag for no event execution
variables.isNoExecution = false;
// the name of the event via URL/FORM/REMOTE
variables.eventName = arguments.properties.eventName;
// Registered Layouts
variables.registeredLayouts = structNew();
if ( structKeyExists( arguments.properties, "registeredLayouts" ) ) {
variables.registeredLayouts = arguments.properties.registeredLayouts;
}
// Registered Folder Layouts
variables.folderLayouts = structNew();
if ( structKeyExists( arguments.properties, "folderLayouts" ) ) {
variables.folderLayouts = arguments.properties.folderLayouts;
}
// Registered View Layouts
variables.viewLayouts = structNew();
if ( structKeyExists( arguments.properties, "viewLayouts" ) ) {
variables.viewLayouts = arguments.properties.viewLayouts;
}
// Private Modules reference
variables.modules = arguments.properties.modules;
// Default layout + View
variables.defaultLayout = arguments.properties.defaultLayout;
variables.defaultView = arguments.properties.defaultView;
// SES Base URL
variables.SESBaseURL = "";
if ( structKeyExists( arguments.properties, "SESBaseURL" ) ) {
variables.SESBaseURL = arguments.properties.SESBaseURL;
}
// routed SES structures
variables.routedStruct = structNew();
// Private Flag for Invalid HTTP Method
variables.invalidHTTPMethod = false;
// Rendering Regions
variables.renderingRegions = {};
// Response Headers
variables.responseHeaders = {};
return this;
}
/***********************************************************************************************************/
/************************************** COLLECTION METHODS *********************************************/
/***********************************************************************************************************/
/**
* Get a representation of this instance
*/
struct function getMemento(){
// Return only non-function elements
return variables.filter( function( key, value ){
return ( !isCustomFunction( value ) );
} );
}
/**
* Override the instance
*/
function setMemento( required struct memento ){
structAppend( variables, arguments.memento, true );
return this;
}
/**
* I Get a reference or deep copy of the public or private request Collection
*
* @deepCopy Default is false, gives a reference to the collection. True, creates a deep copy of the collection.
* @private Use public or private request collection
*/
struct function getCollection( boolean deepCopy = false, boolean private = false ){
// Private Collection
if ( arguments.private ) {
if ( arguments.deepCopy ) {
return duplicate( variables.privateContext );
}
return variables.privateContext;
}
// Public Collection
if ( arguments.deepCopy ) {
return duplicate( variables.context );
}
return variables.context;
}
/**
* I get a private collection
*
* @deepCopy Default is false, gives a reference to the collection. True, creates a deep copy of the collection.
* @private Use public or private request collection
*/
struct function getPrivateCollection( boolean deepCopy = false ){
arguments.private = true;
return getCollection( argumentCollection = arguments );
}
/**
* Clears the entire collection
*
* @private Use public or private request collection
*/
function clearCollection( boolean private = false ){
if ( arguments.private ) {
structClear( variables.privateContext );
} else {
structClear( variables.context );
}
return this;
}
/**
* Clears the private collection
*/
function clearPrivateCollection(){
return clearCollection( private = true );
}
/**
* Append a structure to the collection, with overwrite or not. Overwrite = false by default
*
* @collection The collection to incorporate
* @overwrite Overwrite elements, defaults to false
* @private Private or public, defaults public.
*/
function collectionAppend(
required struct collection,
boolean overwrite = false,
boolean private = false
){
if ( arguments.private ) {
structAppend(
variables.privateContext,
arguments.collection,
arguments.overwrite
);
} else {
structAppend(
variables.context,
arguments.collection,
arguments.overwrite
);
}
return this;
}
/**
* Append a structure to the collection, with overwrite or not. Overwrite = false by default
*
* @collection The collection to incorporate
* @overwrite Overwrite elements, defaults to false
*/
function privateCollectionAppend( required struct collection, boolean overwrite = false ){
arguments.private = true;
return collectionAppend( argumentCollection = arguments );
}
/**
* Get the collection Size
*
* @private Private or public, defaults public.
*/
numeric function getSize( boolean private = false ){
if ( arguments.private ) {
return structCount( variables.privateContext );
}
return structCount( variables.context );
}
/**
* Get the private collection Size
*/
numeric function getPrivateSize(){
return getSize( private = true );
}
/***********************************************************************************************************/
/************************************** VALUE METHODS *********************************************/
/***********************************************************************************************************/
/**
* Get a value from the public or private request collection.
*
* @name The key name
* @defaultValue default value
* @private Private or public, defaults public.
*/
function getValue(
required name,
defaultValue,
boolean private = false
){
var collection = variables.context;
// private context switch
if ( arguments.private ) {
collection = variables.privateContext;
}
// Check if key exists
if ( structKeyExists( collection, arguments.name ) ) {
return collection[ arguments.name ];
}
// Default value
if ( structKeyExists( arguments, "defaultValue" ) ) {
return arguments.defaultValue;
}
throw(
message = "The variable: #arguments.name# is undefined in the request collection (private=#arguments.private#)",
detail = "Keys Found: #structKeyList( collection )#",
type = "RequestContext.ValueNotFound"
);
}
/**
* Get a value from the private request collection.
*
* @name The key name
* @defaultValue default value
*/
function getPrivateValue( required name, defaultValue ){
arguments.private = true;
return getValue( argumentCollection = arguments );
}
/**
* Get a value from the request collection and if simple value, I will trim it.
*
* @name The key name
* @defaultValue default value
* @private Private or public, defaults public.
*/
function getTrimValue(
required name,
defaultValue,
boolean private = false
){
var value = getValue( argumentCollection = arguments );
// Verify if Simple
if ( isSimpleValue( value ) ) {
return trim( value );
}
return value;
}
/**
* Get a trim value from the private request collection.
*
* @name The key name
* @defaultValue default value
*/
function getPrivateTrimValue( required name, defaultValue ){
arguments.private = true;
return getTrimValue( argumentCollection = arguments );
}
/**
* Set a value in the request collection
*
* @name The key name
* @value The value
* @private Private or public, defaults public.
*
* @return RequestContext
*/
function setValue(
required name,
required value,
boolean private = false
){
var collection = variables.context;
if ( arguments.private ) {
collection = variables.privateContext;
}
collection[ arguments.name ] = arguments.value;
return this;
}
/**
* Set a value in the private request collection
*
* @name The key name
* @value The value
*
* @return RequestContext
*/
function setPrivateValue( required name, required value ){
arguments.private = true;
return setValue( argumentCollection = arguments );
}
/**
* remove a value in the request collection
*
* @name The key name
* @private Private or public, defaults public.
*
* @return RequestContext
*/
function removeValue( required name, boolean private = false ){
var collection = variables.context;
if ( arguments.private ) {
collection = variables.privateContext;
}
structDelete( collection, arguments.name );
return this;
}
/**
* remove a value in the private request collection
*
* @name The key name
*
* @return RequestContext
*/
function removePrivateValue( required name, boolean private = false ){
arguments.private = true;
return removeValue( argumentCollection = arguments );
}
/**
* Check if a value exists in the request collection
*
* @name The key name
* @private Private or public, defaults public.
*/
boolean function valueExists( required name, boolean private = false ){
var collection = variables.context;
if ( arguments.private ) {
collection = variables.privateContext;
}
return structKeyExists( collection, arguments.name );
}
/**
* Check if a value exists in the private request collection
*
* @name The key name
*/
boolean function privateValueExists( required name ){
arguments.private = true;
return valueExists( argumentCollection = arguments );
}
/**
* Just like cfparam, but for the request collection
*
* @name The key name
* @value The value
* @private Private or public, defaults public.
*
* @return RequestContext
*/
function paramValue(
required name,
required value,
boolean private = false
){
if ( not valueExists( name = arguments.name, private = arguments.private ) ) {
setValue(
name = arguments.name,
value = arguments.value,
private = arguments.private
);
}
return this;
}
/**
* Just like cfparam, but for the private request collection
*
* @name The key name
* @value The value
*
* @return RequestContext
*/
function paramPrivateValue( required name, required value ){
arguments.private = true;
return paramValue( argumentCollection = arguments );
}
/**
* Filters the collection or private collection down to only the provided keys.
*
* @keys A list or array of keys to bring back from the collection or private collection.
* @private Private or public, defaults public request collection
*/
struct function getOnly( required keys, boolean private = false ){
if ( isSimpleValue( arguments.keys ) ) {
arguments.keys = listToArray( arguments.keys );
}
// determine target context
var thisContext = arguments.private ? variables.privateContext : variables.context;
var returnStruct = {};
for ( var key in arguments.keys ) {
if ( structKeyExists( thisContext, key ) ) {
returnStruct[ key ] = thisContext[ key ];
}
}
return returnStruct;
}
/**
* Filters the private collection down to only the provided keys.
*
* @keys A list or array of keys to bring back from the private collection.
*/
struct function getPrivateOnly( required keys ){
return getOnly( keys = keys, private = true );
}
/**
* Filters the collection or private collection down to all keys except the provided keys.
*
* @keys A list or array of keys to exclude from the results of the collection or private collection.
* @private Private or public, defaults public request collection
*/
struct function getExcept( required keys, boolean private = false ){
if ( isSimpleValue( arguments.keys ) ) {
arguments.keys = listToArray( arguments.keys );
}
// determine target context
var thisContext = arguments.private ? variables.privateContext : variables.context;
var returnStruct = {};
for ( var key in thisContext ) {
if ( !arrayContains( arguments.keys, key ) ) {
returnStruct[ key ] = thisContext[ key ];
}
}
return returnStruct;
}
/**
* Filters the private collection down to all keys except the provided keys.
*
* @keys A list or array of keys to exclude from the results of the private collection.
*/
struct function getPrivateExcept( required keys ){
return getExcept( keys = keys, private = true );
}
/***********************************************************************************************************/
/************************************** CURRENT CONTEXT METHODS **************************************/
/***********************************************************************************************************/
/**
* Gets the current set view the framework will try to render for this request
*/
string function getCurrentView(){
return getPrivateValue( "currentView", "" );
}
/**
* Gets the current set view the framework will try to render for this request
*/
struct function getCurrentViewArgs(){
return getPrivateValue( "currentViewArgs", structNew() );
}
/**
* Gets the current set views's module for rendering
*/
string function getCurrentViewModule(){
return getPrivateValue( "viewModule", "" );
}
/**
* Gets the current set layout for rendering
*/
string function getCurrentLayout(){
return getPrivateValue( "currentLayout", "" );
}
/**
* Gets the current set layout's module for rendering
*/
string function getCurrentLayoutModule(){
return getPrivateValue( "layoutmodule", "" );
}
/**
* Get the current request's route pattern that matched
*/
string function getCurrentRoute(){
return getPrivateValue( "currentRoute", "" );
}
/**
* Get the current request's routed name
*/
string function getCurrentRouteName(){
return getPrivateValue( "currentRouteName", "" );
}
/**
* Get the current routed namespace that matched the route, if any
*/
string function getCurrentRoutedNamespace(){
return getPrivateValue( "currentRoutedNamespace", "" );
}
/**
* Get the current routed module that matched the route, if any
*/
string function getCurrentRoutedModule(){
return getPrivateValue( "currentRoutedModule", "" );
}
/**
* Get the current routed URL that matched the route pattern
*/
string function getCurrentRoutedURL(){
return getPrivateValue( "currentRoutedURL", "" );
}
/**
* Get the current routed route record in all of its raw glory
* Returns an empty struct if no record was found.
*/
struct function getCurrentRouteRecord(){
return getPrivateValue( "currentRouteRecord", {} );
}
/**
* Gets the current routed route's metadata struct, if any
* Returns an empty struct if no record was found.
*/
struct function getCurrentRouteMeta(){
return getPrivateValue( "currentRouteMeta", {} );
}
/**
* Verify if the passed name is the same as the current route name
*
* @name The name to test against the current route
*/
boolean function routeIs( required name ){
return getCurrentRouteName() == arguments.name;
}
/**
* Tests that a given path exists in the currently routed URL.
* If the exact flag is passed, the path must match exactly.
* Using the `urlMatchesExact` is preferred.
*
* @path The path to match in the currently routed URL.
* @exact Flag to do an exact match instead of a partial match
*
* @return Boolean
*/
boolean function urlMatches( required string path, boolean exact = false ){
// Cleanup, routed url never has a `/` in front
arguments.path = reReplace( arguments.path, "^/", "" );
var currentRoutedURL = getCurrentRoutedURL();
if ( arguments.exact ) {
return arguments.path == currentRoutedURL;
}
// if the incoming path to look for is greater than the current routed url, bail out
if ( arguments.path.len() > currentRoutedURL.len() ) {
return false;
}
var replaced = replace( currentRoutedURL, arguments.path, "" );
var sliced = mid(
currentRoutedURL,
len( arguments.path ) + 1,
len( currentRoutedURL ) - len( arguments.path )
);
return replaced == sliced;
}
/**
* Tests that a given path matches exactly to the currently routed URL.
*
* @path The path to match exactly to the currently routed URL.
*
* @return Boolean
*/
boolean function urlMatchesExact( required string path ){
arguments.exact = true;
return urlMatches( argumentCollection = arguments );
}
/**
* Gets the current incoming event
*/
string function getCurrentEvent(){
return getValue( variables.eventName, "" );
}
/**
* Gets the current handler requested in the current event
*/
string function getCurrentHandler(){
var thisEvent = getCurrentEvent();
// If module call, clean it up
if ( find( ":", thisEvent ) ) {
thisEvent = getToken( thisEvent, 2, ":" );
}
var testHandler = reReplace( thisEvent, "\.[^.]*$", "" );
if ( listLen( testHandler, "." ) eq 1 ) {
return testHandler;
}
return listLast( testHandler, "." );
}
/**
* Gets the current action requested in the current event
*/
string function getCurrentAction(){
return listLast( getCurrentEvent(), "." );
}
/**
* Gets the current module name, else returns empty string
*/
string function getCurrentModule(){
var thisEvent = getCurrentEvent();
return ( find( ":", thisEvent ) ? listFirst( thisEvent, ":" ) : "" );
}
/**
* Convenience method to get the current request's module root path. If no module, then returns empty path. You can also get this from the modules settings
*
* @module Optional name of the module you want the root for, defaults to the current running module
*/
string function getModuleRoot( module = "" ){
var theModule = "";
if ( structKeyExists( arguments, "module" ) and len( arguments.module ) ) {
theModule = arguments.module;
} else {
theModule = getCurrentModule();
}
if ( len( theModule ) ) {
return variables.modules[ theModule ].mapping;
}
return "";
}
/**
* Convenience method to get a module's inherited entry point URL, blank if not found
*
* @module Optional name of the module you want the root for, defaults to the current running module
*/
string function getModuleEntryPoint( module = "" ){
var theModule = "";
if ( structKeyExists( arguments, "module" ) and len( arguments.module ) ) {
theModule = arguments.module;
} else {
theModule = getCurrentModule();
}
if ( len( theModule ) ) {
return variables.modules[ theModule ].inheritedEntryPoint;
}
return "";
}
/**
* Are we in SSL or not? This method looks at CGI.SERVER_PORT_SECURE for indication
*/
boolean function isSSL(){
if ( isBoolean( CGI.SERVER_PORT_SECURE ) AND CGI.SERVER_PORT_SECURE ) {
return true;
}
// Add typical proxy headers for SSL
if ( getHTTPHeader( "x-forwarded-proto", "http" ) eq "https" ) {
return true;
}
if ( getHTTPHeader( "x-scheme", "http" ) eq "https" ) {
return true;
}
// CGI.HTTPS
if ( CGI.keyExists( "HTTPS" ) and CGI.HTTPS eq "on" ) {
return true;
}
return false;
}
/**
* Check if the request was made with an invalid HTTP Method
*/
boolean function isInvalidHTTPMethod(){
return variables.invalidHTTPMethod;
}
/**
* Set the invalid http method flag
*/
RequestContext function setIsInvalidHTTPMethod( boolean target = true ){
variables.invalidHTTPMethod = arguments.target;
return this;
}
/**
* Set the request timeout for the request.
*
* @seconds The number of seconds as a time limit
*
* @return RequestContext
*/
RequestContext function setRequestTimeout( required numeric seconds ){
setting requesttimeout=arguments.seconds;
return this;
}
/***********************************************************************************************************/
/************************************** VIEW-LAYOUT METHODS *******************************************/
/***********************************************************************************************************/
/**
* Set the view to render in this request. Private Request Collection Name: currentView, currentLayout
*
* @view The name of the view to set. If a layout has been defined it will assign it, else if will assign the default layout. No extension please
* @args An optional set of arguments that will be available when the view is rendered
* @layout You can override the rendering layout of this setView() call if you want to. Else it defaults to implicit resolution or another override.
* @module The explicit module view
* @noLayout Boolean flag, wether the view sent in will be using a layout or not. Default is false. Uses a pre set layout or the default layout.
* @cache True if you want to cache the rendered view.
* @cacheTimeout The cache timeout in minutes
* @cacheLastAccessTimeout The last access timeout in minutes
* @cacheSuffix Add a cache suffix to the view cache entry. Great for multi-domain caching or i18n caching.
* @cacheProvider The cache provider you want to use for storing the rendered view. By default we use the 'template' cache provider
* @name This triggers a rendering region. This will be the unique name in the request for specifying a rendering region, you can then render it by passing the unique name to the view();
*
* @return RequestContext
*/
function setView(
view,
struct args = {},
layout,
module = "",
boolean noLayout = false,
boolean cache = false,
cacheTimeout = "",
cacheLastAccessTimeout = "",
cacheSuffix = "",
cacheProvider = "template",
name
){
// Do we have an incoming rendering region definition? If we do, store it and return
if ( !isNull( arguments.name ) ) {
variables.renderingRegions[ arguments.name ] = arguments;
return this;
}
// stash the view module
variables.privateContext[ "viewModule" ] = arguments.module;
// Direct Layout Usage
if ( !isNull( arguments.layout ) && len( arguments.layout ) ) {
setLayout( arguments.layout );
}
// else try to discover it.
else if ( NOT arguments.noLayout AND NOT getPrivateValue( name = "layoutoverride", defaultValue = false ) ) {
var discoveredLayout = discoverLayout( arguments.view );
if ( discoveredLayout.len() ) {
setPrivateValue( "currentLayout", discoveredLayout );
}