/// <summary> /// Download file using http. May have server latency as first argument. /// </summary> /// <param name="arguments">The arguments.</param> private static void HttpGetFile(string arguments, bool http2) { string[] args = arguments.Split(' '); string uri = string.Empty; int latency = -1; if (args.Length > 1) { uri = args[1]; try { latency = Convert.ToInt32(args[0]); } catch { } } else if (args.Length > 0) { uri = args[0]; } if (uri == string.Empty) { SMLogger.LogError("HTTPGET needs file name."); return; } // if we have partial path without leading slash, add one if ((uri[0] != '/') && (string.Compare(uri, 0, "http:", 0, 5, true) != 0) && (string.Compare(uri, 0, "https:", 0, 6, true) != 0)) { uri = "/" + uri; } if (uri[0] == '/') { // if session is active prepend http://<HOST>:<PORT> if (session != null && session.State == SMSessionState.Opened) { string portString = string.Empty; if (session.Uri.Port != -1) { // non-default HTTP port portString = ":" + session.Uri.Port.ToString(); } if ("wss".Equals(session.Uri.Scheme, StringComparison.OrdinalIgnoreCase)) { uri = "https://" + session.Uri.Host + portString + uri; } else if ("ws".Equals(session.Uri.Scheme, StringComparison.OrdinalIgnoreCase)) { uri = "http://" + session.Uri.Host + portString + uri; } else { SMLogger.LogError("Unrecognized URL scheme. Specify ws/http or wss/https URL scheme."); } } else { SMLogger.LogError("HTTPGET " + uri + " needs server name. Please use CONNECT to connect to server first."); return; } } if (protocolMonitor != null) { protocolMonitor.LastStartDate = DateTime.Now; } // set server latency if available if (latency >= 0) { serverLatency = latency; } HttpRequest request = new HttpRequest(serverLatency, http2); try { if (protocolMonitor != null) { protocolMonitor.LastHTTPLog = request.GetFile(uri.ToLower()); } else { request.GetFile(uri.ToLower()); } // done downloading, save log data if (protocolMonitor != null) { protocolMonitor.LastEndDate = DateTime.Now; } SaveStats(); } finally { request.Dispose(); } }
/// <summary> /// Download file using http. May have server latency as first argument. /// </summary> /// <param name="arguments">The arguments.</param> private static void HttpGetFile(string arguments, bool http2) { string[] args = arguments.Split(' '); string uri = string.Empty; int latency = -1; if (args.Length > 1) { uri = args[1]; try { latency = Convert.ToInt32(args[0]); } catch { } } else if (args.Length > 0) { uri = args[0]; } if (uri == string.Empty) { Http2Logger.LogError("HTTP11GET needs file name."); return; } // if we have partial path without leading slash, add one if ((uri[0] != '/') && (string.Compare(uri, 0, "http:", 0, 5, true) != 0) && (string.Compare(uri, 0, "https:", 0, 6, true) != 0)) { uri = "/" + uri; } if (uri[0] == '/') { // if session is active prepend http://<HOST>:<PORT> if (session != null && session.State == ProtocolSessionState.Opened) { string portString = string.Empty; if (session.Uri.Port != -1) { // non-default HTTP port portString = ":" + session.Uri.Port.ToString(); } } else { Http2Logger.LogError("HTTPGET " + uri + " needs server name."); return; } } if (protocolMonitor != null) { protocolMonitor.LastStartDate = DateTime.Now; } // set server latency if available if (latency >= 0) { serverLatency = latency; } HttpRequest request = new HttpRequest(serverLatency, http2); try { if (protocolMonitor != null) { protocolMonitor.LastHTTPLog = request.GetFile(uri.ToLower()); } else { request.GetFile(uri.ToLower()); } // done downloading, save log data if (protocolMonitor != null) { protocolMonitor.LastEndDate = DateTime.Now; } SaveStats(); } catch (Exception ex) { Http2Logger.LogError(ex.Message); } finally { request.Dispose(); } }
/// <summary> /// Download file using http. /// </summary> /// <param name="uri">The URI.</param> private static void HttpGetFile(string uri) { if (uri == string.Empty) { SMLogger.LogError("HTTPGET needs file name."); return; } if (uri[0] == '/') { // if session is active prepend http://<HOST>:<PORT> if (session != null && session.State == SMSessionState.Opened) { string portString = string.Empty; if (session.Uri.Port != -1) { // non-default HTTP port portString = ":" + session.Uri.Port.ToString(); } uri = "http://" + session.Uri.Host + portString + uri; } else { SMLogger.LogError("HTTPGET " + uri + " needs server name. Please use CONNECT to connect to server first."); return; } } HttpRequest request = new HttpRequest(); protocolMonitor.LastHTTPLog = request.GetFile(uri); }