@@ -21,16 +21,9 @@ use crate::utils::TruncatableToFit;
21
21
/// to the client.
22
22
#[ derive( Debug ) ]
23
23
pub struct Response {
24
- /// The response's status
25
24
status : StatusCode ,
26
-
27
- /// The response's version
28
25
version : Version ,
29
-
30
- /// The response's headers
31
26
headers : Headers < Self > ,
32
-
33
- /// The body of the response.
34
27
body : String ,
35
28
}
36
29
@@ -67,6 +60,27 @@ impl Response {
67
60
Self :: builder ( ) . ok ( )
68
61
}
69
62
63
+ pub fn redirect < P > ( location : P ) -> ResponseBuilder
64
+ where
65
+ P : Into < String > ,
66
+ {
67
+ Self :: builder ( ) . redirect ( location)
68
+ }
69
+
70
+ pub fn temporary_redirect < P > ( location : P ) -> ResponseBuilder
71
+ where
72
+ P : Into < String > ,
73
+ {
74
+ Self :: builder ( ) . temporary_redirect ( location)
75
+ }
76
+
77
+ pub fn permanent_redirect < P > ( location : P ) -> ResponseBuilder
78
+ where
79
+ P : Into < String > ,
80
+ {
81
+ Self :: builder ( ) . permanent_redirect ( location)
82
+ }
83
+
70
84
/// Returns a response builder with a created status
71
85
/// code.
72
86
pub fn created ( ) -> ResponseBuilder {
@@ -377,6 +391,50 @@ impl ResponseBuilder {
377
391
self
378
392
}
379
393
394
+ pub fn see_other < L > ( mut self , location : L ) -> Self
395
+ where
396
+ L : Into < String > ,
397
+ {
398
+ self . headers . insert ( "Location" , location) ;
399
+ self . status = StatusCode :: SEE_OTHER ;
400
+
401
+ self
402
+ }
403
+
404
+ /// Alias to see_other. Use when the redirect is a
405
+ /// direct response to a POST / PUT action where the
406
+ /// request is intended to go.
407
+ pub fn redirect < L > ( self , location : L ) -> Self
408
+ where
409
+ L : Into < String > ,
410
+ {
411
+ self . see_other ( location)
412
+ }
413
+
414
+ /// Temporary redirect. Use when the resource is now
415
+ /// located at a different URI temporarily.
416
+ pub fn temporary_redirect < L > ( mut self , location : L ) -> Self
417
+ where
418
+ L : Into < String > ,
419
+ {
420
+ self . headers . insert ( "Location" , location) ;
421
+ self . status = StatusCode :: TEMPORARY_REDIRECT ;
422
+
423
+ self
424
+ }
425
+
426
+ /// Permanent redirect. Use when the resource is now
427
+ /// located at a different URI permanently.
428
+ pub fn permanent_redirect < L > ( mut self , location : L ) -> Self
429
+ where
430
+ L : Into < String > ,
431
+ {
432
+ self . headers . insert ( "Location" , location) ;
433
+ self . status = StatusCode :: PERMANENT_REDIRECT ;
434
+
435
+ self
436
+ }
437
+
380
438
pub fn message < M > ( mut self , message : M ) -> Self
381
439
where
382
440
M : Into < String > ,
0 commit comments