Google Cloud Storage v1 API - Class UrlSigner.RequestTemplate (4.3.0)

public sealed class UrlSigner.RequestTemplate

Reference documentation and code samples for the Google Cloud Storage v1 API class UrlSigner.RequestTemplate.

Represents the request template to be signed.

Inheritance

object > UrlSigner.RequestTemplate

Namespace

GoogleGoogle.CloudGoogle.Cloud.StorageV1

Assembly

Google.Cloud.Storage.V1.dll

Remarks

When either of the headers collections are specified, there are certain headers which will be included in the signed URL's signature, and therefore must be included in requests made with the created URL. These are the Content-MD5 and Content-Type content headers as well as any content or request header with a name starting with "x-goog-".

If the headers collections are null or empty, no headers are included in the signed URL's signature, so any requests made with the created URL must not contain Content-MD5, Content-Type, or any header starting with "x-goog-".

Note that when GET is specified as the HttpMethod (or it is null, in which case GET is used), both GET and HEAD requests can be made with the created signed URL.

Properties

Bucket

public string Bucket { get; }

The name of the bucket. This will never be null.

Property Value
TypeDescription
string

ContentHeaders

public IReadOnlyDictionary<string, IReadOnlyCollection<string>> ContentHeaders { get; }

The headers for the content which will be included with the request. This will never be null. If null is specified in WithContentHeaders(IEnumerable<KeyValuePair<string, IEnumerable<string>>>) then an empty dictionary will be used.

Property Value
TypeDescription
IReadOnlyDictionarystringIReadOnlyCollectionstring
Remarks

When using V2, from all the headers supplied in ContentHeaders, only the ones starting with "x-goog-", the Content-MD5 and the Content-Type headers will be included in the signed URL's signature and therefor must be included in requests made with the created URL. All other headers supplied in ContentHeaders will be ignored when creating the signed URL so they shouldn't be included in requests made with the created URL.

When using V4 all headers supplied in ContentHeaders will be included in the signed URL's signature and therefor must be included in requests made with the created URL.

HttpMethod

public HttpMethod HttpMethod { get; }

The HTTP request method for which the signed URL is allowed to be used. This will never be null. If null is specified in WithHttpMethod(HttpMethod) then this value will be set to Get. Will default to Get.

Property Value
TypeDescription
HttpMethod
Remarks

Note that when GET is specified as the HttpMethod, both GET and HEAD requests can be made with the created signed URL.

ObjectName

public string ObjectName { get; }

The name of the object within the bucket. May be null, in which case the signed URL will refer to the bucket instead of an object.

Property Value
TypeDescription
string

QueryParameters

public IReadOnlyDictionary<string, IReadOnlyCollection<string>> QueryParameters { get; }

The query parameters which will be included with the request. This will never be null. If null is specified in WithQueryParameters(IEnumerable<KeyValuePair<string, IEnumerable<string>>>) then an empty dictionary will be used.

Property Value
TypeDescription
IReadOnlyDictionarystringIReadOnlyCollectionstring
Remarks

When using V2 custom query parameters are not supported by the signing process and Sign(RequestTemplate, Options) and SignAsync(RequestTemplate, Options, CancellationToken) will throw ArgumentException if QueryParameters is not an empty dictionary, that is, if one or more custom query parameters have been specified.

RequestHeaders

public IReadOnlyDictionary<string, IReadOnlyCollection<string>> RequestHeaders { get; }

The headers which will be included with the request. This will never be null. If null is specified in WithRequestHeaders(IEnumerable<KeyValuePair<string, IEnumerable<string>>>) then an empty dictionary will be used.

Property Value
TypeDescription
IReadOnlyDictionarystringIReadOnlyCollectionstring
Remarks

When using V2, from all the headers supplied in RequestHeaders, only the ones starting with "x-goog-" will be included in the signed URL's signature and therefor must be included in requests made with the created URL. All other headers supplied in RequestHeaders will be ignored when creating the signed URL so they shouldn't be included in requests made with the created URL.

When using V4 all headers supplied in RequestHeaders will be included in the signed URL's signature and therefor must be included in requests made with the created URL.

Note that if the entity is encrypted with customer-supplied encryption keys (see https://cloud.google.com/storage/docs/encryption for more information), the x-goog-encryption-algorithm, x-goog-encryption-key, and x-goog-encryption-key-sha256 headers will be required when making the request. However, only the x-goog-encryption-algorithm header is included in the signature for the signed URL. So the RequestHeaders specified only need to have the x-goog-encryption-algorithm header.

Methods

FromBucket(string)

public static UrlSigner.RequestTemplate FromBucket(string bucket)

Creates a new request template to sign from the given bucket name.

Parameter
NameDescription
bucketstring

The name of the bucket for which the signed URL will be created. Must not be null.

Returns
TypeDescription
UrlSignerRequestTemplate

A new request template.

WithBucket(string)

public UrlSigner.RequestTemplate WithBucket(string bucket)

Returns a new request template with all the same settings as this one except for the bucket name.

Parameter
NameDescription
bucketstring

The new bucket name. Must not be null.

Returns
TypeDescription
UrlSignerRequestTemplate

A new request template.

WithContentHeaders(IEnumerable<KeyValuePair<string, IEnumerable<string>>>)

public UrlSigner.RequestTemplate WithContentHeaders(IEnumerable<KeyValuePair<string, IEnumerable<string>>> contentHeaders)

Returns a new request template with all the same settings as this one except for the content headers.

Parameter
NameDescription
contentHeadersIEnumerableKeyValuePairstringIEnumerablestring

The new content headers. May be null, in which case an empty collection will be used.

Returns
TypeDescription
UrlSignerRequestTemplate

A new request template.

WithHttpMethod(HttpMethod)

public UrlSigner.RequestTemplate WithHttpMethod(HttpMethod method)

Returns a new request template with all the same settings as this one except for the HTTP method.

Parameter
NameDescription
methodHttpMethod

The new HTTP method. May be null, in which case Get will be used.

Returns
TypeDescription
UrlSignerRequestTemplate

A new request template.

WithHttpRequestMessage(HttpRequestMessage)

public UrlSigner.RequestTemplate WithHttpRequestMessage(HttpRequestMessage requestMessage)

Returns a new request template with all the same settings as this one except for all the information that can be obtained from requestMessage, that is the HTTP method, the request headers and the content headers.

Parameter
NameDescription
requestMessageHttpRequestMessage

The new request message. May be null, in which case the default values for all the affected properties will be used..

Returns
TypeDescription
UrlSignerRequestTemplate

A new request template.

WithObjectName(string)

public UrlSigner.RequestTemplate WithObjectName(string objectName)

Returns a new request template with all the same settings as this one except for the object name.

Parameter
NameDescription
objectNamestring

The new object name. May be null, in which case the signed URL will refer to the bucket instead of an object.

Returns
TypeDescription
UrlSignerRequestTemplate

A new request template.

WithQueryParameters(IEnumerable<KeyValuePair<string, IEnumerable<string>>>)

public UrlSigner.RequestTemplate WithQueryParameters(IEnumerable<KeyValuePair<string, IEnumerable<string>>> queryParameters)

Returns a new request template with all the same settings as this one except for the query parameters.

Parameter
NameDescription
queryParametersIEnumerableKeyValuePairstringIEnumerablestring

The new query parameters. May be null, in which case an empty collection will be used.

Returns
TypeDescription
UrlSignerRequestTemplate

A new request template.

WithRequestHeaders(IEnumerable<KeyValuePair<string, IEnumerable<string>>>)

public UrlSigner.RequestTemplate WithRequestHeaders(IEnumerable<KeyValuePair<string, IEnumerable<string>>> requestHeaders)

Returns a new request template with all the same settings as this one except for the request headers.

Parameter
NameDescription
requestHeadersIEnumerableKeyValuePairstringIEnumerablestring

The new request headers. May be null, in which case an empty collection will be used.

Returns
TypeDescription
UrlSignerRequestTemplate

A new request template.