Skip to content

Commit

Permalink
Add headers to Hosting Version (#12527)
Browse files Browse the repository at this point in the history
  • Loading branch information
rainshen49 authored Dec 10, 2024
1 parent b1ee4b6 commit 93c2b6e
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 25 deletions.
95 changes: 70 additions & 25 deletions mmv1/products/firebasehosting/Version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ base_url: 'sites/{{site_id}}/versions'
self_link: 'sites/{{site_id}}/versions/{{version_id}}'
create_url: 'sites/{{site_id}}/versions'
exclude_delete: true
# not updatable
# not updatable
immutable: true
import_format:
- 'sites/{{site_id}}/versions/{{version_id}}'
Expand All @@ -46,6 +46,20 @@ examples:
site_id: 'site-id'
test_env_vars:
project_id: 'PROJECT_NAME'
- name: 'firebasehosting_version_headers'
primary_resource_id: 'default'
min_version: 'beta'
vars:
site_id: 'site-id'
test_env_vars:
project_id: 'PROJECT_NAME'
- name: 'firebasehosting_version_headers_regex'
primary_resource_id: 'default'
min_version: 'beta'
vars:
site_id: 'site-id'
test_env_vars:
project_id: 'PROJECT_NAME'
- name: 'firebasehosting_version_path'
primary_resource_id: 'default'
min_version: 'beta'
Expand Down Expand Up @@ -126,45 +140,45 @@ properties:
description:
The user-supplied glob to match against the request URL path.
min_version: 'beta'
exactly_one_of:
- 'glob'
- 'regex'
# exactly_one_of:
# - 'glob'
# - 'regex'
- name: 'regex'
type: String
description:
The user-supplied RE2 regular expression to match against the
request URL path.
min_version: 'beta'
exactly_one_of:
- 'glob'
- 'regex'
# exactly_one_of:
# - 'glob'
# - 'regex'
- name: 'path'
type: String
description:
The URL path to rewrite the request to.
min_version: 'beta'
exactly_one_of:
- 'path'
- 'function'
- 'run'
# exactly_one_of:
# - 'path'
# - 'function'
# - 'run'
- name: 'function'
type: String
description:
The function to proxy requests to. Must match the exported
function name exactly.
min_version: 'beta'
exactly_one_of:
- 'path'
- 'function'
- 'run'
# exactly_one_of:
# - 'path'
# - 'function'
# - 'run'
- name: 'run'
type: NestedObject
description: The request will be forwarded to Cloud Run.
min_version: 'beta'
exactly_one_of:
- 'path'
- 'function'
- 'run'
# exactly_one_of:
# - 'path'
# - 'function'
# - 'run'
properties:
- name: 'serviceId'
type: String
Expand Down Expand Up @@ -194,18 +208,18 @@ properties:
description:
The user-supplied glob to match against the request URL path.
min_version: 'beta'
exactly_one_of:
- 'glob'
- 'regex'
# exactly_one_of:
# - 'glob'
# - 'regex'
- name: 'regex'
type: String
description:
The user-supplied RE2 regular expression to match against the
request URL path.
min_version: 'beta'
exactly_one_of:
- 'glob'
- 'regex'
# exactly_one_of:
# - 'glob'
# - 'regex'
- name: 'statusCode'
type: Integer
description:
Expand All @@ -229,3 +243,34 @@ properties:
```
min_version: 'beta'
required: true
- name: 'headers'
type: Array
description: |
An array of objects, where each object specifies a URL pattern that, if matched to the request URL path,
triggers Hosting to apply the specified custom response headers.
item_type:
description: |
A Header specifies a URL pattern that, if matched to the request URL path, triggers Hosting
to apply the specified custom response headers.
type: NestedObject
properties:
- name: 'glob'
type: String
description:
The user-supplied glob to match against the request URL path.
# exactly_one_of:
# - 'glob'
# - 'regex'
- name: 'regex'
type: String
description:
The user-supplied RE2 regular expression to match against the
request URL path.
# exactly_one_of:
# - 'glob'
# - 'regex'
- name: 'headers'
type: KeyValuePairs
description: |
The additional headers to add to the response. Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.
required: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
resource "google_firebase_hosting_site" "default" {
provider = google-beta
project = "{{index $.TestEnvVars "project_id"}}"
site_id = "{{index $.Vars "site_id"}}"
}

resource "google_firebase_hosting_version" "default" {
provider = google-beta
site_id = google_firebase_hosting_site.default.site_id
config {
headers {
# Also okay to use regex
glob = "/headers/**"
headers = {
my-header = "my-value"
}
}
}
}

resource "google_firebase_hosting_release" "default" {
provider = google-beta
site_id = google_firebase_hosting_site.default.site_id
version_name = google_firebase_hosting_version.default.name
message = "With custom headers"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
resource "google_firebase_hosting_site" "default" {
provider = google-beta
project = "{{index $.TestEnvVars "project_id"}}"
site_id = "{{index $.Vars "site_id"}}"
}

resource "google_firebase_hosting_version" "default" {
provider = google-beta
site_id = google_firebase_hosting_site.default.site_id
config {
headers {
# Also okay to use glob
regex = "^~/headers$"
headers = {
my-header = "my-value"
}
}
}
}

resource "google_firebase_hosting_release" "default" {
provider = google-beta
site_id = google_firebase_hosting_site.default.site_id
version_name = google_firebase_hosting_version.default.name
message = "With custom headers"
}

0 comments on commit 93c2b6e

Please sign in to comment.