Beispiel #1
0
        //TODO: will be needing a GZippedResponse (for large underlying streams)
        internal static HttpResponse GZipFunc(HttpResponse origResp)
        {
            var byteArrayBody = origResp.Body as HttpBody.ByteArray;
            if (byteArrayBody != null)
            {
                var newHeaders = new Dictionary<string, string>(origResp.Headers, StringComparer.OrdinalIgnoreCase)
                {
                    { HttpHeader.ContentEncoding, HttpHeaderValue.GZip }
                };

                return new HttpResponse(origResp.StatusCode,
                                        origResp.StatusDescription,
                                        origResp.ContentType,
                                        newHeaders,
                                        new HttpBody.ByteArray(Compression.GZip(byteArrayBody.Bytes)));
            }

            //TODO: if body is a HttpBody.Streamable

            return origResp; // pass-through (unzipped) for now
        }
Beispiel #2
0
 public static HttpResponse GZip(IHttpRequest req, HttpResponse resp) => defaultGZipFilter(req, resp);
Beispiel #3
0
        public int WriteResponse(HttpResponse response, bool keepAlive)
        {
            using (var outputBuffer = new MemoryStream(512 + response.Body.Length))
            {
                int bytesToWrite = HttpResponseWriter.Write(response, outputBuffer, keepAlive ? KeepAlivesRemaining : 0, readTimeout);
                Write(outputBuffer.GetBuffer(), 0, bytesToWrite);

                return bytesToWrite;
            }
        }
        static void WriteAndCloseResponse(HttpResponse httpResp, HttpListenerResponse respCtx)
        {
            try
            {
                respCtx.StatusCode = (int)httpResp.StatusCode;
                respCtx.StatusDescription = httpResp.StatusDescription;
                respCtx.ContentType = httpResp.ContentType;

                if (httpResp.Headers != null && httpResp.Headers.Count > 0)
                {
                    foreach (var kvp in httpResp.Headers)
                    {
                        respCtx.Headers[kvp.Key] = kvp.Value;
                    }
                }

                var body = httpResp.Body;
                if (body != null && body.Length > 0)
                {
                    respCtx.ContentLength64 = body.Length;
                    respCtx.OutputStream.Write(body, 0, body.Length);
                    respCtx.OutputStream.Flush();
                    respCtx.OutputStream.Close();
                }

                respCtx.Close();
            }
            catch (Exception)
            {
                return;
            }
        }
Beispiel #5
0
 public static HttpResponse GZip(IHttpRequest req, HttpResponse resp) => GZip(GZipFunc)(req, resp);
Beispiel #6
0
 public static HttpResponse GZip(IHttpRequest req, HttpResponse resp) => GZip(GZipFunc)(req, resp);