package com.l7tech.common.http.prov.jdk;

import com.l7tech.common.http.GenericHttpException;
import com.l7tech.common.http.GenericHttpHeader;
import com.l7tech.common.http.GenericHttpHeaders;
import com.l7tech.common.http.GenericHttpRequest;
import com.l7tech.common.http.GenericHttpRequestParams;
import com.l7tech.common.http.GenericHttpResponse;
import com.l7tech.common.http.HttpHeader;
import com.l7tech.common.http.HttpMethod;
import com.l7tech.common.mime.ContentTypeHeader;
import com.l7tech.util.IOUtils;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;

class b implements GenericHttpRequest {
   boolean a;
   private InputStream b;
   final GenericHttpRequestParams val$params;
   final HttpMethod val$method;
   final URLConnection val$conn;
   final HttpURLConnection val$httpConn;
   private static final String[] c;

   b(UrlConnectionHttpClient var1, GenericHttpRequestParams var2, HttpMethod var3, URLConnection var4, HttpURLConnection var5) {
      this.val$params = var2;
      this.val$method = var3;
      this.val$conn = var4;
      this.val$httpConn = var5;
      this.a = false;
      this.b = null;
   }

   @Override
   public void setInputStream(InputStream var1) {
      try {
         if (!this.val$params.needsRequestBody(this.val$method)) {
            throw new UnsupportedOperationException(c[2] + this.val$method);
         }
      } catch (UnsupportedOperationException var2) {
         throw a(var2);
      }

      try {
         if (this.a) {
            throw new IllegalStateException(c[0]);
         }
      } catch (UnsupportedOperationException var3) {
         throw a(var3);
      }

      this.b = var1;
   }

   @Override
   public void addParameters(List<String[]> var1) throws IllegalArgumentException, IllegalStateException {
      throw new IllegalStateException(c[1]);
   }

   @Override
   public GenericHttpResponse getResponse() throws GenericHttpException {
      try {
         try {
            if (this.b != null) {
               IOUtils.copyStream(this.b, this.val$conn.getOutputStream());
            }
         } catch (IOException var10) {
            throw a(var10);
         }

         int var1 = this.val$httpConn.getResponseCode();
         String var2 = this.val$conn.getContentType();

         ContentTypeHeader var10000;
         label42: {
            try {
               if (var2 != null) {
                  var10000 = ContentTypeHeader.create(var2);
                  break label42;
               }
            } catch (IOException var9) {
               throw a(var9);
            }

            var10000 = null;
         }

         ContentTypeHeader var3 = var10000;
         ArrayList var4 = new ArrayList();
         int var5 = 0;

         String var6;
         do {
            String var7 = this.val$httpConn.getHeaderFieldKey(var5);
            var6 = this.val$httpConn.getHeaderField(var5);
            if (var7 != null) {
               try {
                  if (var6 != null) {
                     var4.add(new GenericHttpHeader(var7, var6));
                  }
               } catch (IOException var8) {
                  throw a(var8);
               }
            }

            var5++;
         } while (var6 != null);

         GenericHttpHeaders var12 = new GenericHttpHeaders(var4.toArray(new HttpHeader[var4.size()]));
         this.a = true;
         return new a(this, var1, var12, var3);
      } catch (IOException var11) {
         throw new GenericHttpException(var11);
      }
   }

   @Override
   public void close() {
      try {
         if (!this.a) {
            this.val$httpConn.disconnect();
            this.a = true;
         }
      } catch (UnsupportedOperationException var1) {
         throw a(var1);
      }
   }

   private static Exception a(Exception var0) {
      return var0;
   }

   static {
      String[] var5 = new String[3];
      int var3 = 0;
      String var2 = "E(&obA2E\u0010on'x\u0013t3;<+zFp,=y#m\u001f1##s1l\u0002Ke(&ob`\u000ba,*q'g\u0012p4&s,)\tw`;t')!t.*n+j.e4?N'x\u0013t3;<&f\u0003b`!s6)\u0015d0?s0}Fp$+L#{\u0007|%;y0/s/+e\u000bg\u0016d4\u001ch0l\u0007|`!s6)\bt%+y&)\u0000~2on'x\u0013t3;</l\u0012y/+&b";
      int var4 = "E(&obA2E\u0010on'x\u0013t3;<+zFp,=y#m\u001f1##s1l\u0002Ke(&ob`\u000ba,*q'g\u0012p4&s,)\tw`;t')!t.*n+j.e4?N'x\u0013t3;<&f\u0003b`!s6)\u0015d0?s0}Fp$+L#{\u0007|%;y0/s/+e\u000bg\u0016d4\u001ch0l\u0007|`!s6)\bt%+y&)\u0000~2on'x\u0013t3;</l\u0012y/+&b"
         .length();
      char var1 = '#';
      int var0 = -1;

      while (true) {
         String var10002 = a(44, a(var2.substring(++var0, var0 + var1)));
         byte var10001 = -1;
         var5[var3++] = var10002;
         if ((var0 += var1) >= var4) {
            c = var5;
            return;
         }

         var1 = var2.charAt(var0);
      }
   }

   private static char[] a(String var0) {
      char[] var10000 = var0.toCharArray();
      if (var10000.length < 2) {
         var10000[0] = (char)(var10000[0] ^ 74);
      }

      return var10000;
   }

   private static String a(int var0, char[] var1) {
      int var10003 = var1.length;
      int var10002 = var0;
      char[] var10001 = var1;
      int var10000 = var10003;

      for (int var2 = 0; var10000 > var2; var2++) {
         var10001[var2] = (char)(var10001[var2] ^ var10002 ^ switch (var2 % 7) {
            case 0 -> 61;
            case 1 -> 108;
            case 2 -> 99;
            case 3 -> 48;
            case 4 -> 110;
            case 5 -> 37;
            default -> 74;
         });
      }

      return new String(var10001).intern();
   }
}
