Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Sources/Functions/FunctionsClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,20 @@ public final class FunctionsClient: Sendable {
private func buildRequest(functionName: String, options: FunctionInvokeOptions)
-> Helpers.HTTPRequest
{
var query = options.query
var request = HTTPRequest(
url: url.appendingPathComponent(functionName),
method: FunctionInvokeOptions.httpMethod(options.method) ?? .post,
query: options.query,
query: query,
headers: mutableState.headers.merging(with: options.headers),
body: options.body,
timeoutInterval: FunctionsClient.requestIdleTimeout
)

if let region = options.region ?? region {
request.headers[.xRegion] = region
query.appendOrUpdate(URLQueryItem(name: "forceFunctionRegion", value: region))
request.query = query
}

return request
Expand Down
6 changes: 4 additions & 2 deletions Tests/FunctionsTests/FunctionsClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ final class FunctionsClientTests: XCTestCase {

Mock(
url: url.appendingPathComponent("hello-world"),
ignoreQuery: true,
statusCode: 200,
data: [.post: Data()]
)
Expand All @@ -174,7 +175,7 @@ final class FunctionsClientTests: XCTestCase {
--header "X-Client-Info: functions-swift/0.0.0" \
--header "apikey: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0" \
--header "x-region: ca-central-1" \
"http://localhost:5432/functions/v1/hello-world"
"http://localhost:5432/functions/v1/hello-world?forceFunctionRegion=ca-central-1"
"""#
}
.register()
Expand All @@ -185,6 +186,7 @@ final class FunctionsClientTests: XCTestCase {
func testInvokeWithRegion() async throws {
Mock(
url: url.appendingPathComponent("hello-world"),
ignoreQuery: true,
statusCode: 200,
data: [.post: Data()]
)
Expand All @@ -195,7 +197,7 @@ final class FunctionsClientTests: XCTestCase {
--header "X-Client-Info: functions-swift/0.0.0" \
--header "apikey: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0" \
--header "x-region: ca-central-1" \
"http://localhost:5432/functions/v1/hello-world"
"http://localhost:5432/functions/v1/hello-world?forceFunctionRegion=ca-central-1"
"""#
}
.register()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ curl \
--header "apikey: supabase.anon.key" \
--header "x-client-info: functions-swift/x.y.z" \
--header "x-region: ap-northeast-1" \
"http://localhost:5432/functions/v1/hello-world"
"http://localhost:5432/functions/v1/hello-world?forceFunctionRegion=ap-northeast-1"
Loading