3636import java .util .List ;
3737import java .util .Map ;
3838
39- import javajs . util . Lst ;
39+ import sun . net . www . MessageHeader ;
4040
4141/**
4242 * The abstract class <code>URLConnection</code> is the superclass of all
@@ -368,7 +368,7 @@ public OutputStream getOutputStream() throws IOException {
368368 throw new UnknownServiceException ("protocol doesn't support output" );
369369 }
370370
371- private Lst < String []> requests ;
371+ private MessageHeader requests ;
372372
373373 /**
374374 * Sets the general request property. If a property with the key already
@@ -395,14 +395,9 @@ public void setRequestProperty(String key, String value) {
395395 throw new IllegalStateException ("Already connected" );
396396 if (key == null )
397397 throw new NullPointerException ("key is null" );
398- if (requests == null )
399- requests = new Lst <String []>();
400- for (int i = requests .size (); --i >= 0 ;)
401- if (requests .get (i )[0 ].equals (key )) {
402- requests .get (i )[1 ] = value ;
403- return ;
404- }
405- requests .addLast (new String [] { key , value });
398+ if (requests == null )
399+ requests = new MessageHeader ();
400+ requests .set (key , value );
406401 }
407402
408403
@@ -548,73 +543,67 @@ public void setDefaultUseCaches(boolean defaultusecaches) {
548543 }
549544
550545
551- /**
552- * Adds a general request property specified by a
553- * key-value pair. This method will not overwrite
554- * existing values associated with the same key.
555- *
556- * @param key the keyword by which the request is known
557- * (e.g., "<code>accept</code>").
558- * @param value the value associated with it.
559- * @throws IllegalStateException if already connected
560- * @throws NullPointerException if key is null
561- * @see #getRequestProperties()
562- * @since 1.4
563- */
564- public void addRequestProperty (String key , String value ) {
565- if (connected )
566- throw new IllegalStateException ("Already connected" );
567- if (key == null )
568- throw new NullPointerException ("key is null" );
569-
570- // if (requests == null)
571- // requests = new MessageHeader();
572- //
573- // requests.add(key, value);
574- }
546+ /**
547+ * Adds a general request property specified by a key-value pair. This method
548+ * will not overwrite existing values associated with the same key.
549+ *
550+ * @param key the keyword by which the request is known (e.g.,
551+ * "<code>accept</code>").
552+ * @param value the value associated with it.
553+ * @throws IllegalStateException if already connected
554+ * @throws NullPointerException if key is null
555+ * @see #getRequestProperties()
556+ * @since 1.4
557+ */
558+ public void addRequestProperty (String key , String value ) {
559+ if (connected )
560+ throw new IllegalStateException ("Already connected" );
561+ if (key == null )
562+ throw new NullPointerException ("key is null" );
575563
564+ if (requests == null )
565+ requests = new MessageHeader ();
576566
577- /**
578- * Returns the value of the named general request property for this
579- * connection.
580- *
581- * @param key the keyword by which the request is known (e.g., "accept").
582- * @return the value of the named general request property for this
583- * connection. If key is null, then null is returned.
584- * @throws IllegalStateException if already connected
585- * @see #setRequestProperty(java.lang.String, java.lang.String)
586- */
587- public String getRequestProperty (String key ) {
588- if (connected )
589- throw new IllegalStateException ("Already connected" );
567+ requests .add (key , value );
568+ }
590569
591- // if (requests == null)
592- return null ;
593570
594- // return requests.findValue(key);
595- }
571+ /**
572+ * Returns the value of the named general request property for this connection.
573+ *
574+ * @param key the keyword by which the request is known (e.g., "accept").
575+ * @return the value of the named general request property for this connection.
576+ * If key is null, then null is returned.
577+ * @throws IllegalStateException if already connected
578+ * @see #setRequestProperty(java.lang.String, java.lang.String)
579+ */
580+ public String getRequestProperty (String key ) {
581+ if (connected )
582+ throw new IllegalStateException ("Already connected" );
583+ if (requests == null )
584+ return null ;
585+ return requests .findValue (key );
586+ }
596587
597- /**
598- * Returns an unmodifiable Map of general request
599- * properties for this connection. The Map keys
600- * are Strings that represent the request-header
601- * field names. Each Map value is a unmodifiable List
602- * of Strings that represents the corresponding
603- * field values.
604- *
605- * @return a Map of the general request properties for this connection.
606- * @throws IllegalStateException if already connected
607- * @since 1.4
608- */
609- public Map <String ,List <String >> getRequestProperties () {
610- if (connected )
611- throw new IllegalStateException ("Already connected" );
588+ /**
589+ * Returns an unmodifiable Map of general request properties for this
590+ * connection. The Map keys are Strings that represent the request-header field
591+ * names. Each Map value is a unmodifiable List of Strings that represents the
592+ * corresponding field values.
593+ *
594+ * @return a Map of the general request properties for this connection.
595+ * @throws IllegalStateException if already connected
596+ * @since 1.4
597+ */
598+ public Map <String , List <String >> getRequestProperties () {
599+ if (connected )
600+ throw new IllegalStateException ("Already connected" );
612601
613- // if (requests == null)
614- return Collections .EMPTY_MAP ;
602+ if (requests == null )
603+ return Collections .EMPTY_MAP ;
615604
616- // return requests.getHeaders(null);
617- }
605+ return requests .getHeaders (null );
606+ }
618607
619608 /**
620609 * Sets the default value of a general request property. When a
0 commit comments