@@ -127,15 +127,14 @@ class BaseRequestData(BaseModel):
127127 method : HttpMethod = 'GET'
128128 """HTTP request method."""
129129
130- headers : Annotated [HttpHeaders , Field (default_factory = HttpHeaders () )] = HttpHeaders ()
130+ headers : Annotated [HttpHeaders , Field (default_factory = HttpHeaders )] = HttpHeaders ()
131131 """HTTP request headers."""
132132
133133 query_params : Annotated [HttpQueryParams , Field (alias = 'queryParams' , default_factory = dict )] = {}
134134 """URL query parameters."""
135135
136- payload : HttpPayload | None = None
137-
138- data : Annotated [dict [str , Any ], Field (default_factory = dict )] = {}
136+ payload : Annotated [HttpPayload , Field (default_factory = dict )] = {}
137+ """HTTP request payload."""
139138
140139 user_data : Annotated [
141140 dict [str , JsonSerializable ], # Internally, the model contains `UserData`, this is just for convenience
@@ -169,6 +168,8 @@ def from_url(
169168 url : str ,
170169 * ,
171170 method : HttpMethod = 'GET' ,
171+ headers : HttpHeaders | None = None ,
172+ query_params : HttpQueryParams | None = None ,
172173 payload : HttpPayload | None = None ,
173174 label : str | None = None ,
174175 unique_key : str | None = None ,
@@ -178,6 +179,10 @@ def from_url(
178179 ** kwargs : Any ,
179180 ) -> Self :
180181 """Create a new `BaseRequestData` instance from a URL. See `Request.from_url` for more details."""
182+ headers = headers or HttpHeaders ()
183+ query_params = query_params or {}
184+ payload = payload or {}
185+
181186 unique_key = unique_key or compute_unique_key (
182187 url ,
183188 method = method ,
@@ -193,6 +198,8 @@ def from_url(
193198 unique_key = unique_key ,
194199 id = id ,
195200 method = method ,
201+ headers = headers ,
202+ query_params = query_params ,
196203 payload = payload ,
197204 ** kwargs ,
198205 )
@@ -243,6 +250,8 @@ def from_url(
243250 url : str ,
244251 * ,
245252 method : HttpMethod = 'GET' ,
253+ headers : HttpHeaders | None = None ,
254+ query_params : HttpQueryParams | None = None ,
246255 payload : HttpPayload | None = None ,
247256 label : str | None = None ,
248257 unique_key : str | None = None ,
@@ -261,6 +270,8 @@ def from_url(
261270 Args:
262271 url: The URL of the request.
263272 method: The HTTP method of the request.
273+ headers: The HTTP headers of the request.
274+ query_params: The query parameters of the URL.
264275 payload: The data to be sent as the request body. Typically used with 'POST' or 'PUT' requests.
265276 label: A custom label to differentiate between request types. This is stored in `user_data`, and it is
266277 used for request routing (different requests go to different handlers).
@@ -274,6 +285,10 @@ def from_url(
274285 computation. This is only relevant when `unique_key` is not provided.
275286 **kwargs: Additional request properties.
276287 """
288+ headers = headers or HttpHeaders ()
289+ query_params = query_params or {}
290+ payload = payload or {}
291+
277292 unique_key = unique_key or compute_unique_key (
278293 url ,
279294 method = method ,
@@ -289,6 +304,8 @@ def from_url(
289304 unique_key = unique_key ,
290305 id = id ,
291306 method = method ,
307+ headers = headers ,
308+ query_params = query_params ,
292309 payload = payload ,
293310 ** kwargs ,
294311 )
@@ -377,6 +394,36 @@ def forefront(self) -> bool:
377394 def forefront (self , new_value : bool ) -> None :
378395 self .crawlee_data .forefront = new_value
379396
397+ def __eq__ (self , other : object ) -> bool :
398+ """Compare all relevant fields of the `Request` class, excluding deprecated fields `json_` and `order_no`.
399+
400+ TODO: Remove this method once the issue is resolved.
401+ https://github.com/apify/crawlee-python/issues/94
402+ """
403+ if isinstance (other , Request ):
404+ return (
405+ self .url == other .url
406+ and self .unique_key == other .unique_key
407+ and self .method == other .method
408+ and self .headers == other .headers
409+ and self .query_params == other .query_params
410+ and self .payload == other .payload
411+ and self .user_data == other .user_data
412+ and self .retry_count == other .retry_count
413+ and self .no_retry == other .no_retry
414+ and self .loaded_url == other .loaded_url
415+ and self .handled_at == other .handled_at
416+ and self .id == other .id
417+ and self .label == other .label
418+ and self .state == other .state
419+ and self .max_retries == other .max_retries
420+ and self .session_rotation_count == other .session_rotation_count
421+ and self .enqueue_strategy == other .enqueue_strategy
422+ and self .last_proxy_tier == other .last_proxy_tier
423+ and self .forefront == other .forefront
424+ )
425+ return NotImplemented
426+
380427
381428class RequestWithLock (Request ):
382429 """A crawling request with information about locks."""
0 commit comments