Instance Methodvapor 4.106.3Vapor
redirect(to:type:)
Creates a redirect Response
.
This declaration has been renamed to Request.redirect(to:redirectType:).
This declaration is deprecated.
func redirect(to location: String, type: RedirectType) -> Response
Parameters
Returns
A response that provides a redirect to the specified location
router.get("redirect") { req in
return req.redirect(to: "https://vapor.codes")
}
Set type to ‘.permanently’ to allow caching to automatically redirect from browsers. Defaulting to non-permanent to prevent unexpected caching.
Other members in extension
Types
struct Authentication
Request helper for storing and fetching authenticated objects.
struct Body
struct Password
Type members
init(application: Application, method: HTTPMethod, url: URI, version: HTTPVersion, headers: HTTPHeaders, collectedBody: ByteBuffer?, remoteAddress: SocketAddress?, logger: Logger, byteBufferAllocator: ByteBufferAllocator, on: EventLoop
) init(application: Application, method: HTTPMethod, url: URI, version: HTTPVersion, headersNoUpdate: HTTPHeaders, collectedBody: ByteBuffer?, remoteAddress: SocketAddress?, logger: Logger, byteBufferAllocator: ByteBufferAllocator, on: EventLoop
) static func decodeRequest(Request
) -> EventLoopFuture<Request> static func decodeRequest(Request
) async throws -> Request
Instance members
let application: Application
var auth: Authentication
Helper for accessing authenticated objects. See
Authenticator
for more information.var body: Body
var byteBufferAllocator: ByteBufferAllocator
var cache: Cache
var client: Client
var content: ContentContainer
This container is used to read your
Decodable
type using aContentDecoder
implementation. If noContentDecoder
is provided, aRequest
’sContent-Type
header is used to select a registered decoder.var description: String
See
CustomStringConvertible
let eventLoop: EventLoop
The
EventLoop
which is handling thisRequest
. The route handler and any relevant middleware are invoked in this event loop.var fileio: FileIO
var hasSession: Bool
var headers: HTTPHeaders
The header fields for this HTTP request. The
"Content-Length"
and"Transfer-Encoding"
headers will be set automatically when thebody
property is mutated.let id: String
A unique ID for the request.
var logger: Logger
This Logger from Apple’s
swift-log
Package is preferred when logging in the context of handing this Request. Vapor already provides metadata to this logger so that multiple logged messages can be traced back to the same request.var method: HTTPMethod
The HTTP method for this request.
var parameters: Parameters
A container containing the route parameters that were captured when receiving this request. Use this container to grab any non-static parameters from the URL, such as model IDs in a REST API.
var password: Password
var peerAddress: SocketAddress?
We try to determine true peer address if load balancer or reversed proxy provided info in headers
var query: URLQueryContainer
let remoteAddress: SocketAddress?
The address from which this HTTP request was received by SwiftNIO. This address may not represent the original address of the peer, especially if Vapor receives its requests through a reverse-proxy such as nginx.
var route: Route?
Route object we found for this request. This holds metadata that can be used for (for example) Metrics.
var session: Session
Returns the current
Session
or creates one.var storage: Storage
This container is used as arbitrary request-local storage during the request-response lifecycle.Z
var url: URI
The URL used on this request.
var version: HTTPVersion
The version for this HTTP request.
var view: ViewRenderer
func redirect(to: String, redirectType: Redirect
) -> Response Creates a redirect
Response
.func webSocket(maxFrameSize: WebSocketMaxFrameSize, shouldUpgrade: @escaping ((Request) -> EventLoopFuture<HTTPHeaders?>), onUpgrade: @escaping (Request, WebSocket) -> ()
) -> Response func webSocket(maxFrameSize: WebSocketMaxFrameSize, shouldUpgrade: @escaping ((Request) async throws -> HTTPHeaders?), onUpgrade: @escaping (Request, WebSocket) async -> ()
) -> Response Upgrades an existing request to a websocket connection