@@ -18,6 +18,7 @@ class Request {
1818
1919 this . _body = this . _body ?? new Body ( options . body ) ;
2020 this . method = options . method ?? this . method ;
21+ this . method = this . method . toUpperCase ( ) ;
2122
2223 if ( this . _body . _bodyInit && [ "GET" , "HEAD" ] . includes ( this . method ) ) {
2324 throw new TypeError ( "Body not allowed for GET or HEAD requests" ) ;
@@ -34,6 +35,8 @@ class Request {
3435 if ( ! this . headers . has ( "content-type" ) && this . _body . _mimeType ) {
3536 this . headers . set ( "content-type" , this . _body . _mimeType ) ;
3637 }
38+
39+ this . __handleCacheOption ( options . cache ) ;
3740 }
3841
3942 __handleRequestInput ( request , options ) {
@@ -49,6 +52,34 @@ class Request {
4952 }
5053 }
5154
55+ __handleCacheOption ( cache ) {
56+ if ( ! [ "GET" , "HEAD" ] . includes ( this . method ) ) {
57+ return ;
58+ }
59+
60+ if ( ! [ "no-store" , "no-cache" ] . includes ( cache ) ) {
61+ return ;
62+ }
63+
64+ const currentTime = Date . now ( ) ;
65+ // Search for a '_' parameter in the query string
66+ const querySearchRegExp = / ( [ ? & ] ) _ = [ ^ & ] * / ;
67+
68+ if ( querySearchRegExp . test ( this . url ) ) {
69+ this . url = this . url . replace (
70+ querySearchRegExp ,
71+ `$1_=${ currentTime } `
72+ ) ;
73+
74+ return ;
75+ }
76+
77+ const hasQueryRegExp = / \? / ;
78+ const querySeparator = hasQueryRegExp . test ( this . url ) ? "&" : "?" ;
79+
80+ this . url += `${ querySeparator } _=${ currentTime } ` ;
81+ }
82+
5283 get bodyUsed ( ) {
5384 return this . _body . bodyUsed ;
5485 }
0 commit comments