@@ -16,6 +16,7 @@ use diesel_async::AsyncPgConnection;
16
16
use futures_util:: future:: BoxFuture ;
17
17
use futures_util:: { FutureExt , TryStreamExt } ;
18
18
use http:: header;
19
+ use http:: request:: Parts ;
19
20
use indexmap:: IndexMap ;
20
21
use serde:: { Deserialize , Serialize } ;
21
22
@@ -76,8 +77,8 @@ impl PaginationOptionsBuilder {
76
77
self
77
78
}
78
79
79
- pub ( crate ) fn gather < T : RequestPartsExt > ( self , req : & T ) -> AppResult < PaginationOptions > {
80
- let params = req . query ( ) ;
80
+ pub ( crate ) fn gather ( self , parts : & Parts ) -> AppResult < PaginationOptions > {
81
+ let params = parts . query ( ) ;
81
82
let page_param = params. get ( "page" ) ;
82
83
let seek_param = params. get ( "seek" ) ;
83
84
@@ -100,16 +101,16 @@ impl PaginationOptionsBuilder {
100
101
}
101
102
102
103
if numeric_page > MAX_PAGE_BEFORE_SUSPECTED_BOT {
103
- req . request_log ( ) . add ( "bot" , "suspected" ) ;
104
+ parts . request_log ( ) . add ( "bot" , "suspected" ) ;
104
105
}
105
106
106
107
// Block large offsets for known violators of the crawler policy
107
108
if self . limit_page_numbers {
108
- let config = & req . app ( ) . config ;
109
+ let config = & parts . app ( ) . config ;
109
110
if numeric_page > config. max_allowed_page_offset
110
- && is_useragent_or_ip_blocked ( config, req )
111
+ && is_useragent_or_ip_blocked ( config, parts )
111
112
{
112
- req . request_log ( ) . add ( "cause" , "large page offset" ) ;
113
+ parts . request_log ( ) . add ( "cause" , "large page offset" ) ;
113
114
114
115
let error =
115
116
format ! ( "Page {numeric_page} is unavailable for performance reasons. Please take a look at https://crates.io/data-access for alternatives." ) ;
@@ -739,12 +740,14 @@ mod tests {
739
740
) ;
740
741
}
741
742
742
- fn mock ( query : & str ) -> Request < ( ) > {
743
+ fn mock ( query : & str ) -> Parts {
743
744
Request :: builder ( )
744
745
. method ( Method :: GET )
745
746
. uri ( format ! ( "/?{query}" ) )
746
747
. body ( ( ) )
747
748
. unwrap ( )
749
+ . into_parts ( )
750
+ . 0
748
751
}
749
752
750
753
fn assert_pagination_error ( options : PaginationOptionsBuilder , query : & str , message : & str ) {
0 commit comments