public async Task <IHttpActionResult> Forward() { var requestStream = await Request.Content.ReadAsStreamAsync().ConfigureAwait(false); OnPremiseConnectorResponse response = null; if (Request.Headers.TryGetValues("X-TTRELAY-METADATA", out var headerValues)) { response = JToken.Parse(headerValues.First()).ToObject <OnPremiseConnectorResponse>(); using (var stream = _postDataTemporaryStore.CreateResponseStream(response.RequestId)) { await requestStream.CopyToAsync(stream).ConfigureAwait(false); response.ContentLength = stream.Length; } } else { // this is a legacy on-premise connector (v1) response = await ForwardLegacyResponse(Encoding.UTF8, requestStream).ConfigureAwait(false); } _logger?.Verbose("Received on-premise response. request-id={RequestId}, content-length={ResponseContentLength}", response.RequestId, response.ContentLength); _backendCommunication.SendOnPremiseTargetResponse(response.OriginId, response); return(Ok()); }
public async Task <IHttpActionResult> Forward() { var claimsPrincipal = (ClaimsPrincipal)RequestContext.Principal; var onPremiseId = claimsPrincipal.FindFirst(AuthorizationServerProvider.OnPremiseIdClaimName)?.Value; Request.GetCallCancelled().Register(() => _logger?.Warning("Disconnect during receiving on-premise response detected. link-id={LinkId}", onPremiseId)); var requestStream = await Request.Content.ReadAsStreamAsync().ConfigureAwait(false); OnPremiseConnectorResponse response = null; if (Request.Headers.TryGetValues("X-TTRELAY-METADATA", out var headerValues)) { response = JToken.Parse(headerValues.First()).ToObject <OnPremiseConnectorResponse>(); using (var stream = _postDataTemporaryStore.CreateResponseStream(response.RequestId)) { await requestStream.CopyToAsync(stream).ConfigureAwait(false); response.ContentLength = stream.Length; } } else { // this is a legacy on-premise connector (v1) response = await ForwardLegacyResponse(Encoding.UTF8, requestStream).ConfigureAwait(false); } _logger?.Verbose("Received on-premise response. request-id={RequestId}, content-length={ResponseContentLength}", response.RequestId, response.ContentLength); _backendCommunication.SendOnPremiseTargetResponse(response.OriginId, response); return(Ok()); }
public async Task <OkResult> Forward(JToken message) { _logger.Trace("Forwarding {0}", message.ToString()); var onPremiseTargetReponse = message.ToObject <OnPremiseTargetReponse>(); await _backendCommunication.SendOnPremiseTargetResponse(onPremiseTargetReponse.OriginId, onPremiseTargetReponse); return(Ok()); }