private Task <TResp> SendRequestInternalAsync <TReq, TResp>(TReq request, CancellationToken token) where TResp : IResponse, new() where TReq : IRequest { request.Timestamp = DateTimeOffset.UtcNow; request.RequestId = Guid.NewGuid(); _logger.LogTrace("Handling {RequestType} with request id {RequestId}", typeof(TReq).Name, request.RequestId); Stream?requestStream = _marshaller.MarshalRequest(_config, request); _requestValidator.ValidateAndThrow(request); IEndpointData endpointData = _endpointBuilder.GetEndpoint(request); request.SetHeader(HttpHeaders.Host, endpointData.Host); request.SetHeader(AmzHeaders.XAmzDate, request.Timestamp, DateTimeFormat.Iso8601DateTime); if (requestStream != null) { foreach (IRequestStreamWrapper wrapper in _requestStreamWrappers) { if (wrapper.IsSupported(request)) { requestStream = wrapper.Wrap(requestStream, request); } } } if (!request.Headers.TryGetValue(AmzHeaders.XAmzContentSha256, out string contentHash)) { if (_config.PayloadSignatureMode == SignatureMode.Unsigned) { contentHash = "UNSIGNED-PAYLOAD"; } else { contentHash = requestStream == null ? Constants.EmptySha256 : CryptoHelper.Sha256Hash(requestStream, true).HexEncode(); } request.SetHeader(AmzHeaders.XAmzContentSha256, contentHash); } _logger.LogDebug("ContentSha256 is {ContentSha256}", contentHash); //We add the authorization header here because we need ALL other headers to be present when we do _authBuilder.BuildAuthorization(request); StringBuilder sb = StringBuilderPool.Shared.Rent(200); sb.Append(endpointData.Endpoint); RequestHelper.AppendPath(sb, _config, request); RequestHelper.AppendQueryParameters(sb, request); string url = StringBuilderPool.Shared.ReturnString(sb); return(HandleResponse <TReq, TResp>(request, url, requestStream, token)); }
public string SignRequest <TReq>(TReq request, TimeSpan expiresIn) where TReq : IRequest { request.Timestamp = DateTimeOffset.UtcNow; request.RequestId = Guid.NewGuid(); _logger.LogTrace("Handling {RequestType} with request id {RequestId}", typeof(TReq).Name, request.RequestId); _marshaller.MarshalRequest(_config, request); IEndpointData endpointData = _endpointBuilder.GetEndpoint(request); request.SetHeader(HttpHeaders.Host, endpointData.Host); string scope = _scopeBuilder.CreateScope("s3", request.Timestamp); request.SetQueryParameter(AmzParameters.XAmzAlgorithm, SigningConstants.AlgorithmTag); request.SetQueryParameter(AmzParameters.XAmzCredential, _config.Credentials.KeyId + '/' + scope); request.SetQueryParameter(AmzParameters.XAmzDate, request.Timestamp.ToString(DateTimeFormats.Iso8601DateTime, DateTimeFormatInfo.InvariantInfo)); request.SetQueryParameter(AmzParameters.XAmzExpires, expiresIn.TotalSeconds.ToString(NumberFormatInfo.InvariantInfo)); request.SetQueryParameter(AmzParameters.XAmzSignedHeaders, string.Join(";", HeaderWhitelist.FilterHeaders(request.Headers).Select(x => x.Key))); //Copy all headers to query parameters foreach (KeyValuePair <string, string> header in request.Headers) { if (header.Key == HttpHeaders.Host) { continue; } request.SetQueryParameter(header.Key, header.Value); } _authBuilder.BuildAuthorization(request); //Clear sensitive material from the request if (request is IContainSensitiveMaterial sensitive) { sensitive.ClearSensitiveMaterial(); } StringBuilder sb = StringBuilderPool.Shared.Rent(200); sb.Append(endpointData.Endpoint); RequestHelper.AppendPath(sb, _config, request); RequestHelper.AppendQueryParameters(sb, request); return(StringBuilderPool.Shared.ReturnString(sb)); }
public IEndpointData Endpoint() { return(_builder2.GetEndpoint(_request)); }
public IEndpointData EndpointTemplate() { return(_builder.GetEndpoint(_request)); }