public void WriteResponse(IHttpResponseWrapper response) { if (this.OriginAllowed != null) { response.AddHeader(CorsConstants.ResponseHeader_AllowOrign, this.OriginAllowed); } if (this.AreCookiesAllowed == true) { response.AddHeader(CorsConstants.ResponseHeader_AllowCookies, "true"); } if (this.AllowedMethods != null && this.AllowedMethods.Any()) { var methods = this.AllowedMethods.Aggregate((x, y) => x + "," + y); response.AddHeader(CorsConstants.ResponseHeader_AllowMethods, methods); } if (this.AllowedRequestHeaders != null && this.AllowedRequestHeaders.Any()) { var headers = this.AllowedRequestHeaders.Aggregate((x, y) => x + "," + y); response.AddHeader(CorsConstants.ResponseHeader_AllowRequestHeaders, headers); } if (this.AllowedResponseHeaders != null && this.AllowedResponseHeaders.Any()) { var headers = this.AllowedResponseHeaders.Aggregate((x, y) => x + "," + y); response.AddHeader(CorsConstants.ResponseHeader_AllowResponseHeaders, headers); } if (this.ResponseCacheDurationSeconds.HasValue) { response.AddHeader(CorsConstants.ResponseHeader_CacheDuration, this.ResponseCacheDurationSeconds.Value.ToString()); } }
protected virtual void SetStatusCode(RequestInfo requestInfo, IHttpResponseWrapper response) { // extension point, override to add logic in inheritors. // currently used by DynamicResponseCreator in order to let script code override status code response.HttpStatusCode = (HttpStatusCode)StatusCode; }
public LoginAmplaSessionUsingQueryString(IHttpRequestWrapper requestWrapper, IHttpResponseWrapper responseWrapper, IAmplaUserService amplaUserService, IFormsAuthenticationService formsAuthenticationService, IAmplaSessionStorage amplaSessionStorage) { this.requestWrapper = requestWrapper; this.responseWrapper = responseWrapper; this.amplaUserService = amplaUserService; this.formsAuthenticationService = formsAuthenticationService; this.amplaSessionStorage = amplaSessionStorage; }
protected virtual void SetContentType(RequestInfo requestInfo, IHttpResponseWrapper response) { // extension point, override to add logic in inheritors. // currently used by DynamicResponseCreator in order to let script code override content type if (ContentType != null) { var contenttype = ContentType; contenttype += $"; charset={Encoding.WebName}"; response.ContentType = contenttype; } }
protected override void SetContentType(RequestInfo requestInfo, IHttpResponseWrapper response) { Debug.Assert(requestInfo != null); Debug.Assert(response != null); if (requestInfo.ContentType != RequestInfo.USE_CONFIGURED_CONTENT_TYPE) { response.ContentType = requestInfo.ContentType; } else { base.SetContentType(requestInfo, response); } }
protected override void SetStatusCode(RequestInfo requestInfo, IHttpResponseWrapper response) { Debug.Assert(requestInfo != null); Debug.Assert(response != null); if (requestInfo.StatusCode != RequestInfo.USE_CONFIGURED_STATUS_CODE) { response.HttpStatusCode = (HttpStatusCode)requestInfo.StatusCode; } else { base.SetStatusCode(requestInfo, response); } }
public override async Task <byte[]> CreateResponseAsync(IHttpRequestWrapper request, byte[] requestBody, IHttpResponseWrapper response, Endpoint endpoint) { var requestInfo = new RequestInfo { RequestPath = request.Path.ToString(), QueryString = request.QueryString.ToString(), RequestBody = Encoding.UTF8.GetString(requestBody), Headers = request.Headers, Endpoint = endpoint }; var responseBody = await GetBodyAndExecuteReplacementsAsync(requestInfo); SetContentType(requestInfo, response); SetStatusCode(requestInfo, response); await response.WriteAsync(responseBody, Encoding); return(Encoding.GetBytes(responseBody)); }
public abstract Task <byte[]> CreateResponseAsync(IHttpRequestWrapper request, byte[] requestBody, IHttpResponseWrapper response, Endpoint endpoint);
/// <summary> /// Initializes a new instance of the <see cref="FormsAuthenticationService"/> class. /// </summary> /// <param name="request">The request.</param> /// <param name="response">The response.</param> public FormsAuthenticationService(IHttpRequestWrapper request, IHttpResponseWrapper response) { this.request = request; this.response = response; }
public override async Task <byte[]> CreateResponseAsync(IHttpRequestWrapper request, byte[] body, IHttpResponseWrapper response, string endpointDirectory) { var requestPath = request.Path.ToString(); if (StripPath != null) { requestPath = Regex.Replace(requestPath, StripPath, ""); } var httpMsg = new HttpRequestMessage(HttpMethod.Post, Url + requestPath); Debug.Assert(request.Headers != null); foreach (var header in request.Headers) { if (!HEADERS_TO_SKIP.Contains(header.Key.ToLower())) { httpMsg.Headers.Add(header.Key, header.Value.ToArray()); } } httpMsg.Content = new ByteArrayContent(body); if ((string)request.Headers["Content-Type"] != null) { httpMsg.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(request.Headers["Content-Type"]); } var httpClient = ProxyUrl == null ? new HttpClient() : new HttpClient(new HttpClientHandler { UseProxy = true, Proxy = new WebProxy(ProxyUrl, false) }); var responseMessage = await httpClient.SendAsync(httpMsg); response.ContentType = responseMessage.Content.Headers.ContentType.ToString(); var responseBodyStream = await responseMessage.Content.ReadAsStreamAsync(); var memoryStream = new MemoryStream(); responseBodyStream.CopyTo(memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); memoryStream.CopyTo(response.Body); return(memoryStream.ToArray()); }
public override async Task <byte[]> CreateResponseAsync(IHttpRequestWrapper request, byte[] requestBody, IHttpResponseWrapper response, string endpointDirectory) { var responseBody = GetBodyAndExecuteReplacements(new RequestInfo { RequestPath = request.Path.ToString(), QueryString = request.QueryString.ToString(), RequestBody = Encoding.UTF8.GetString(requestBody), Headers = request.Headers, EndpointDirectory = endpointDirectory }); if (ContentType != null) { var contenttype = ContentType; contenttype += $"; charset={Encoding.WebName}"; response.ContentType = contenttype; } await response.WriteAsync(responseBody, Encoding); return(Encoding.GetBytes(responseBody)); }
public abstract Task <byte[]> CreateResponseAsync(IHttpRequestWrapper request, byte[] requestBody, IHttpResponseWrapper response, string endpointDirectory);