Uploaded image for project: 'Thrift'
  1. Thrift
  2. THRIFT-1162

THttpClient - provide ReadByte() method for server response

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Trivial
    • Resolution: Incomplete
    • None
    • None
    • C# - Library
    • win2k, .net2

    • Patch Available

    Description

      For now THttpClient supports just one way to read data from server response - the method Read(byte[] buf, int off, int len). But at the moment of getting data user don't know size of getting data so can't determine size of array instance exactly (see sample below).
      By example,
      server code (simple asp.net app):

      public class post : IHttpHandler {
          
          public void ProcessRequest (HttpContext context) {
      		if (context.Request.UserAgent=="C#/THttpClient") {
      			context.Response.ContentType = "application/text";
      			context.Response.ContentEncoding = System.Text.Encoding.Default;
      			context.Response.Write("thrift server response");
      		}
          }
      ...
      

      client code (console app):

      Uri uri = new Uri("http://localhost:3968/TimeServerSample/post.ashx");
      THttpClient transport = new THttpClient(uri);
      transport.Proxy = WebRequest.DefaultWebProxy;
      string postData = "test";
      transport.Write(UTF8Encoding.UTF8.GetBytes(postData));
      transport.Flush();
      byte[] arr = new byte[1024];
      transport.Read(arr, 0, 1024);
      Console.WriteLine(System.Text.UTF8Encoding.UTF8.GetString(arr));
      

      Would be better to define (in addition to Read) method ReadByte (like public method in Stream class) for getting byte array byte for a byte. Something like that:

      System.Collections.ArrayList al = new System.Collections.ArrayList();
      int res = 0;
      while ( res != -1) {
        res = transport.ReadByte();
        if (res > -1) al.Add((byte)res);
      }
      byte[] bytes = (byte[])al.ToArray(typeof(byte));
      

      Attachments

        1. THttpClient.cs
          5 kB
          alex_gs

        Activity

          People

            Unassigned Unassigned
            ag9 alex_gs
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 4m
                4m
                Remaining:
                Remaining Estimate - 4m
                4m
                Logged:
                Time Spent - Not Specified
                Not Specified