public HttpRequest(IHttpHeader header, Stream inputStream, Uri absRequestUri, IHttpResponseSender httpResponseSender) { _header = header ?? throw new ArgumentNullException(nameof(header)); _responseSender = httpResponseSender ?? throw new ArgumentNullException(nameof(httpResponseSender)); InputStream = inputStream ?? throw new ArgumentNullException(nameof(inputStream)); AbsRequestUri = absRequestUri ?? throw new ArgumentNullException(nameof(absRequestUri)); }
public bool ReadHeader(out IHttpHeader header) { string nextLine; if (!string.IsNullOrEmpty(bufferedLine)) { nextLine = bufferedLine; bufferedLine = string.Empty; } else { nextLine = reader.ReadLine(); } if (!string.IsNullOrWhiteSpace(nextLine)) { header = HttpHeader.Parse(nextLine); return(true); } else { header = null; return(false); } }
public void AddHeader(IHttpHeader header) { var knownHeader = Headers.SingleOrDefault(h => string.Equals(h.Name, header.Name, StringComparison.OrdinalIgnoreCase)); _headers.Remove(knownHeader); _headers.Add(header); }
public void Add(IHttpHeader header) { if (header != null && !ContainsHeader(header.Key)) { headers.Add(header.Key, header); } }
/// <summary> /// 将<see cref="IHttpHeader"/>的所有标头复制到另一个<see cref="HttpHeaders"/>中 /// </summary> /// <param name="header">待复制标头的<see cref="IHttpHeader"/></param> /// <param name="bclHeader"><paramref name="header"/>的所有标头将被复制到这个参数中</param> private static void CopyHeader(this IHttpHeader header, HttpHeaders bclHeader) { foreach (var(key, value) in header.Headers()) { bclHeader.Add(key, value); } }
private static void AddHeaderIfNotNull(IHttpHeader contentEncodingHeader, HttpServerResponse newResponse) { if (contentEncodingHeader != null) { newResponse.AddHeader(contentEncodingHeader); } }
public static string EncodeToJwt(IHttpHeader info) { string json = info.WriteJson(); //var publicKey = fCertificate.GetRSAPublicKey(); string token = JWT.JWT.Encode(json, SecretKey, JweAlgorithm.PBES2_HS256_A128KW, JweEncryption.A256CBC_HS512); return(token); }
internal void AddHeader(IHttpHeader header) { if (IsComplete) { throw new InvalidOperationException("Can't add header after processing request is finished!"); } header.Visit(HttpRequestHandleHeaderData.Default, this); _headers.Add(header); }
public Stream Create(Stream inputStream, IHttpHeader header) { if (inputStream == null) { throw new ArgumentNullException(nameof(inputStream)); } if (header == null) { throw new ArgumentNullException(nameof(header)); } var streamTmp = inputStream; var contentLength = header.Headers.ContentLength.Value; if (contentLength != null) { if (contentLength <= 0) { return(new NullInputStream()); } streamTmp = new FixLengthInputStream(streamTmp, contentLength.Value); } foreach (var transferEncodingValue in header.Headers.TransferEncoding.Values) { var cleanedTransferEncoding = transferEncodingValue.ToLower().Trim(); switch (cleanedTransferEncoding) { case "identity": break; case "gzip": streamTmp = new GZipStream(streamTmp, CompressionLevel.Fastest); break; case "deflate": streamTmp = new DeflateStream(streamTmp, CompressionLevel.Fastest); break; case "chunked": streamTmp = new ChunkedInputStream(streamTmp); break; default: throw new InputTransferEncodingNotSupportedException(); } } return(streamTmp); }
public void Add(IHttpHeader header) { CoreValidator.ThrowIfNull(header, nameof(header)); string headerKey = header.Key; if (!this.headers.ContainsKey(headerKey)) { this.headers[headerKey] = new List <IHttpHeader>(); } this.headers[headerKey].Add(header); }
public void AddHeader(IHttpHeader header) { if (header != null) { if (!ContainsHeader(header.Key)) { headers.Add(header.Key, header); } else { SetHeader(header); } } }
public void SetHeader(IHttpHeader header) { if (header != null) { if (!ContainsHeader(header.Key)) { AddHeader(header); } else { headers[header.Key] = header; } } }
public void op_CopyTo_IHttpHeader_int() { var item = new HttpHeader("name", "value"); var obj = new HttpHeaderCollection { item }; var array = new IHttpHeader[1]; obj.CopyTo(array, 0); Assert.Equal(item, (HttpHeader)array[0]); }
private static int GetHeaderOrder(IHttpHeader header) { string[] headerOrder = new[] { "host", "connection", "accept", "user-agent", }; int order = headerOrder.IndexOf(header.Name.ToLowerInvariant()); return(order < 0 ? headerOrder.Length : order); }
private void ParseCookies() { IHttpHeader cookieHeader = Headers.SingleOrDefault(h => h.Key == GlobalConstants.CookieRequestHeaderKey); if (cookieHeader != null) { string[] cookies = cookieHeader.Value.Split("; "); foreach (var cookie in cookies) { string[] cookieAttributes = cookie.Split('=', 2); string cookieName = cookieAttributes[0]; string cookieValue = cookieAttributes[1]; var httpCookie = new HttpCookie(cookieName, cookieValue); Cookies.Add(httpCookie); } } }
public async Task Invoke(HttpContext context, IHttpHeader httpHeader) { var request = context.Request; if (request.Headers.ContainsKey("X-Request-ID")) { httpHeader.CurrentRequestHeaders.Add("X-Request-ID", request.Headers["X-Request-ID"]); } if (request.Headers.ContainsKey("X-Correlation-ID")) { httpHeader.CurrentRequestHeaders.Add("X-Correlation-ID", request.Headers["X-Correlation-ID"]); } if (request.Headers.ContainsKey("X-Application-ID")) { httpHeader.CurrentRequestHeaders.Add("X-Application-ID", request.Headers["X-Application-ID"]); } await _next.Invoke(context); }
public static bool TrySetHeader(this WebHeaderCollection headerCollection, IHttpHeader header) { return(TrySetHeader(headerCollection, header.Name, header.Value)); }
public void RemoveHeader(IHttpHeader header) { _headers.Remove(header); }
public ClientBase(IHttpHeader header) { _header = header; }
public void Add(IHttpHeader header) { Headers.Add(header); is_valid = TriStateValidation.NotSet; }
public static bool TryDownloadHeader(this IHttpChannel channel, string url, out IHttpHeader header) { header = new HttpHeader("plain", 0); var success = new Tryify <IHttpHeader?>() .TryInvoke(() => channel.DownloadHeader(url), out var result, fallback: default);
public static void SetHeader(this HttpWebRequest httpWebRequest, IHttpHeader header) { SetHeader(new HttpWebRequestAdapter(httpWebRequest), header); }
public static void SetHeader(this IHttpWebRequest httpWebRequest, IHttpHeader header) { SetHeader(httpWebRequest, header.Name, header.Value); }
public SampleApiClient(IHttpHeader header, IOptions <ApiConfiguration> options) : base(header) { _options = options; _appName = _options.Value.AppName; }
public void AddHeader(IHttpHeader header) { Headers.Add(header); }