public void SendResponse(Socket socket, bool useSocks) { try { IPEndPoint localEndPoint = (IPEndPoint)socket.LocalEndPoint; string proxy = GetPACAddress(localEndPoint, useSocks); var pac = PacContent.Replace("__PROXY__", $"\"{proxy}\""); string responseHead = $@"HTTP/1.1 200 OK Server: ShadowsocksWindowsElder/{Program.Version} Content-Type: application/x-ns-proxy-autoconfig Content-Length: { Encoding.UTF8.GetBytes(pac).Length} Connection: Close "; byte[] response = Encoding.UTF8.GetBytes(responseHead + pac); socket.BeginSend(response, 0, response.Length, 0, new AsyncCallback(SendCallback), socket); Utils.ReleaseMemory(true); } catch (Exception e) { Logging.LogUsefulException(e); socket.Close(); } }
private byte[] ProcessMethod(SocketAsyncEventArgs arg) { //var msg = Encoding.UTF8.GetString(arg.Buffer, arg.Offset, arg.BytesTransferred); var pac = PacContent.Replace("__PROXY__", $"\"PROXY {(_config.shareOverLan ? LanIP : "127.0.0.1")}:{_config.localPort};\""); string responseHead = $@"HTTP/1.1 200 OK Server: V2RayShell/{Global.Version} Content-Type: application/x-ns-proxy-autoconfig Content-Length: { Encoding.UTF8.GetBytes(pac).Length} Connection: Close "; return(Encoding.UTF8.GetBytes(responseHead + pac)); }