Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. HttpResponse Compression... ?

HttpResponse Compression... ?

Scheduled Pinned Locked Moved C#
sysadminperformancequestionlearning
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Trapper Hell
    wrote on last edited by
    #1

    [Intro] To keep the story short, I have created a Download manager creating various simultaneous HttpRequests and downloading the HttpResponses (of the files). In brief, the relevant code looks somewhat like this... dRequest = (HttpWebRequest)WebRequest.Create(txtURL.Text); dRequest.AddRange(dFrom, dTo); dResponse = (HttpWebResponse)dRequest.GetResponse(); Stream dStream = dResponse.GetResponseStream(); ..And of course the download is saved etc etc etc. This all works fine. [End of Intro] Today I was told that I should enable compression (from the server side - whenever possible) when downloading the file in order to speed up the download even more... However, I have no idea how this works or how this can be achieved? I am not asking for someone to do the code for me (although any examples are appreciated), but I would like to know how this can be achieved / how the system works, or what to search for, in order to achieve this? Huge thanks! :-D

    C S 2 Replies Last reply
    0
    • T Trapper Hell

      [Intro] To keep the story short, I have created a Download manager creating various simultaneous HttpRequests and downloading the HttpResponses (of the files). In brief, the relevant code looks somewhat like this... dRequest = (HttpWebRequest)WebRequest.Create(txtURL.Text); dRequest.AddRange(dFrom, dTo); dResponse = (HttpWebResponse)dRequest.GetResponse(); Stream dStream = dResponse.GetResponseStream(); ..And of course the download is saved etc etc etc. This all works fine. [End of Intro] Today I was told that I should enable compression (from the server side - whenever possible) when downloading the file in order to speed up the download even more... However, I have no idea how this works or how this can be achieved? I am not asking for someone to do the code for me (although any examples are appreciated), but I would like to know how this can be achieved / how the system works, or what to search for, in order to achieve this? Huge thanks! :-D

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Trapper-Hell wrote:

      Today I was told that I should enable compression (from the server side - whenever possible) when downloading the file in order to speed up the download even more... However, I have no idea how this works or how this can be achieved?

      Isn't it a setting in IIS? http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/d52ff289-94d3-4085-bc4e-24eb4f312e0e.mspx?mfr=true[^]

      Man who stand on hill with mouth open wait long time for roast duck to drop in

      1 Reply Last reply
      0
      • T Trapper Hell

        [Intro] To keep the story short, I have created a Download manager creating various simultaneous HttpRequests and downloading the HttpResponses (of the files). In brief, the relevant code looks somewhat like this... dRequest = (HttpWebRequest)WebRequest.Create(txtURL.Text); dRequest.AddRange(dFrom, dTo); dResponse = (HttpWebResponse)dRequest.GetResponse(); Stream dStream = dResponse.GetResponseStream(); ..And of course the download is saved etc etc etc. This all works fine. [End of Intro] Today I was told that I should enable compression (from the server side - whenever possible) when downloading the file in order to speed up the download even more... However, I have no idea how this works or how this can be achieved? I am not asking for someone to do the code for me (although any examples are appreciated), but I would like to know how this can be achieved / how the system works, or what to search for, in order to achieve this? Huge thanks! :-D

        S Offline
        S Offline
        saurabh sahay
        wrote on last edited by
        #3

        Please go through the following article which contains exactly what you need Using HTTP Compression for Faster Downloads[^] If you need to increase the speed further then you may use the below code which actually deals in sockets and increases the speed to many folds when parallel downloading is going on. public class MyWebResponse { public MyWebResponse() { } public void Connect(MyWebRequest request) { ResponseUri = request.RequestUri; socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint remoteEP = new IPEndPoint(Dns.Resolve(ResponseUri.Host).AddressList[0], ResponseUri.Port); socket.Connect(remoteEP); } public void SendRequest(MyWebRequest request) { ResponseUri = request.RequestUri; request.Header = request.Method + " " + ResponseUri.PathAndQuery + " HTTP/1.0\r\n" + request.Headers; socket.Send(Encoding.ASCII.GetBytes(request.Header)); } public void SetTimeout(int Timeout) { socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, Timeout * 1000); socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, Timeout * 1000); } public void ReceiveHeader() { Header = ""; Headers = new WebHeaderCollection(); byte[] bytes = new byte[10]; while (socket.Receive(bytes, 0, 1, SocketFlags.None) > 0) { Header += Encoding.ASCII.GetString(bytes, 0, 1); if (bytes[0] == '\n' && Header.EndsWith("\r\n\r\n")) break; } MatchCollection matches = new Regex("[^\r\n]+").Matches(Header.TrimEnd('\r', '\n')); for (int n = 1; n < matches.Count; n++) { string[] strItem = matches[n].Value.Split(new char[] { ':' }, 2); if (strItem.Length > 0) Headers[strItem[0].Trim()] = strItem[1].Trim(); } // check if the page should be transfered to another location if (matches.Count > 0 && ( matches[0].Value.IndexO

        T 1 Reply Last reply
        0
        • S saurabh sahay

          Please go through the following article which contains exactly what you need Using HTTP Compression for Faster Downloads[^] If you need to increase the speed further then you may use the below code which actually deals in sockets and increases the speed to many folds when parallel downloading is going on. public class MyWebResponse { public MyWebResponse() { } public void Connect(MyWebRequest request) { ResponseUri = request.RequestUri; socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint remoteEP = new IPEndPoint(Dns.Resolve(ResponseUri.Host).AddressList[0], ResponseUri.Port); socket.Connect(remoteEP); } public void SendRequest(MyWebRequest request) { ResponseUri = request.RequestUri; request.Header = request.Method + " " + ResponseUri.PathAndQuery + " HTTP/1.0\r\n" + request.Headers; socket.Send(Encoding.ASCII.GetBytes(request.Header)); } public void SetTimeout(int Timeout) { socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, Timeout * 1000); socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, Timeout * 1000); } public void ReceiveHeader() { Header = ""; Headers = new WebHeaderCollection(); byte[] bytes = new byte[10]; while (socket.Receive(bytes, 0, 1, SocketFlags.None) > 0) { Header += Encoding.ASCII.GetString(bytes, 0, 1); if (bytes[0] == '\n' && Header.EndsWith("\r\n\r\n")) break; } MatchCollection matches = new Regex("[^\r\n]+").Matches(Header.TrimEnd('\r', '\n')); for (int n = 1; n < matches.Count; n++) { string[] strItem = matches[n].Value.Split(new char[] { ':' }, 2); if (strItem.Length > 0) Headers[strItem[0].Trim()] = strItem[1].Trim(); } // check if the page should be transfered to another location if (matches.Count > 0 && ( matches[0].Value.IndexO

          T Offline
          T Offline
          Trapper Hell
          wrote on last edited by
          #4

          Thanks mate! It appears to be just what I wanted... Looks more complex then the methods I'm currently using but I guess that's the way to go... Thanks a lot ;)

          S 1 Reply Last reply
          0
          • T Trapper Hell

            Thanks mate! It appears to be just what I wanted... Looks more complex then the methods I'm currently using but I guess that's the way to go... Thanks a lot ;)

            S Offline
            S Offline
            saurabh sahay
            wrote on last edited by
            #5

            You welcome buddy :)

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups