void client_AnswerReceived(HttpResponse item) { Service s = Service.BuildService(item); if (s != null && ServiceFound != null) ServiceFound(s); }
private void ReplyError(IPEndPoint ep, Exception e, HttpStatusCode code) { HttpResponse response = new HttpResponse(); StreamWriter sw = new StreamWriter(response.Body); sw.Write(e.ToString()); response.ResponseCode = HttpStatusCode.NotImplemented; response.ResponseMessage = e.Message; Reply(ep, response); }
private static HttpResponse Parse(string responseString) { HttpResponse response = new HttpResponse(); StringReader reader = new StringReader(responseString); string line = reader.ReadLine(); string[] firstLine = line.Split(' '); //VERSION RESPONSECODE RESPONSEMESSAGE response.HttpVersion = HttpVersion.HTTP11; response.ResponseCode = (HttpStatusCode)int.Parse(firstLine[1]); response.ResponseMessage = string.Join(" ", firstLine, 2, firstLine.Length - 2); response.ReadHeaders(reader); StreamWriter sw = new StreamWriter(response.Body); sw.Write(reader.ReadToEnd()); response.Body.Seek(0, SeekOrigin.Begin); return response; }
public RequestEventArgs() { Response = new HttpResponse(); }
private void Reply(IPEndPoint ep, HttpResponse response) { byte[] responseBytes = response.GetBytes(); client.Send(responseBytes, responseBytes.Length, ep); }
internal static Service BuildService(HttpResponse item) { Service s = new Service(); if (item.Headers.ContainsKey("ST")) s.Protocol = item.Headers["ST"]; if (item.Headers.ContainsKey("NT")) s.Protocol = item.Headers["NT"]; s.properties = item.Headers; if (item.Headers.ContainsKey("LOCATION")) { s.Location = new Uri(item.Headers["LOCATION"]); s.properties.Remove("LOCATION"); } s.properties.Remove("ST"); s.Addresses.Add(new Network.Dns.EndPoint() { }); if (s.Location != null) s.Addresses[0].Addresses.Add(IPAddress.Parse(s.Location.Host)); if (item.Headers.ContainsKey("CACHE-CONTROL")) { string cacheControl = item.Headers["CACHE-CONTROL"]; int startOfMaxAge = cacheControl.IndexOf("max-age=", StringComparison.InvariantCultureIgnoreCase); int endOfMaxAge = cacheControl.IndexOf(";", startOfMaxAge); if (endOfMaxAge == -1) endOfMaxAge = cacheControl.Length; string ttl = cacheControl.Substring(startOfMaxAge + 8, endOfMaxAge - (startOfMaxAge + 8)); s.expiration = DateTime.Now.AddSeconds(int.Parse(ttl)); } return s; }