public static IObservable <HttpResponse> ResponseObservable(this HttpConnection connection , HttpRequest request , HttpCookieManager cookie , HttpResponse redirectFrom = null ) { // setup read var subject = new ChunkedHttpResponseObserver(); subject.OnNext(connection); var observable = ( from statusline in subject.StatusObservable from headers in subject.HeaderObservable.ToArray() select new HttpResponse(request.Uri , cookie , statusline, headers , redirectFrom) ) .Do(x => { // connect body stream to response subject.BodyObservable.Subscribe(x.CreateBodyObserver()); }) ; // SendRequest connection.SendRequestObservable(request).Subscribe(y => { }); return(observable); }
public HttpRequest(Uri uri, HttpCookieManager cookie) { Major = 1; Minor = 1; Uri = uri; SetHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240"); SetHeader("Host", uri.Host); if (cookie != null) { var cookievalue = cookie.GetRequestValue(); if (!String.IsNullOrEmpty(cookievalue)) { SetHeader("Cookie", cookievalue); } } }
public HttpResponse(Uri uri , HttpCookieManager cookie , String statusline , IEnumerable <KeyValuePair <String, String> > headers , HttpResponse redirectFrom = null ) { Uri = uri; Cookie = cookie != null ? cookie : new HttpCookieManager(); Statusline = statusline; StatusCode = int.Parse(statusline.Split().Skip(1).First()); Headers = headers.ToList(); // parser cookie foreach (var kv in headers) { if (kv.Key.ToLower() == "set-cookie") { Cookie.Push(uri, kv.Value); } } }