Changeset 8cb503d


Ignore:
Timestamp:
Dec 15, 2013 3:16:54 PM (6 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
01b1534, 2b39d28
Parents:
efff25a
Message:

EepGet?: Allow override of the User-Agent
i2psnark: Set User-Agent

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • apps/i2psnark/java/src/org/klomp/snark/I2PSnarkUtil.java

    refff25a r8cb503d  
    7777    public static final String PROP_MAX_BW = "i2cp.outboundBytesPerSecond";
    7878    public static final boolean DEFAULT_USE_DHT = true;
     79    public static final String EEPGET_USER_AGENT = "I2PSnark";
    7980
    8081    public I2PSnarkUtil(I2PAppContext ctx) {
     
    394395        }
    395396        EepGet get = new I2PSocketEepGet(_context, _manager, retries, out.getAbsolutePath(), fetchURL);
     397        get.addHeader("User-Agent", EEPGET_USER_AGENT);
    396398        if (get.fetch(timeout)) {
    397399            if (_log.shouldLog(Log.DEBUG))
     
    435437        ByteArrayOutputStream out = new ByteArrayOutputStream(initialSize);
    436438        EepGet get = new I2PSocketEepGet(_context, _manager, retries, -1, maxSize, null, out, fetchURL);
     439        get.addHeader("User-Agent", EEPGET_USER_AGENT);
    437440        if (get.fetch(timeout)) {
    438441            if (_log.shouldLog(Log.DEBUG))
  • apps/i2psnark/java/src/org/klomp/snark/web/FetchAndAdd.java

    refff25a r8cb503d  
    1919import net.i2p.util.SecureFile;
    2020
     21import org.klomp.snark.I2PSnarkUtil;
    2122import org.klomp.snark.MetaInfo;
    2223import org.klomp.snark.Snark;
     
    131132        _eepGet = new I2PSocketEepGet(_ctx, manager, RETRIES, out.getAbsolutePath(), _url);
    132133        _eepGet.addStatusListener(this);
     134        _eepGet.addHeader("User-Agent", I2PSnarkUtil.EEPGET_USER_AGENT);
    133135        if (_eepGet.fetch()) {
    134136            if (_log.shouldLog(Log.DEBUG))
  • apps/ministreaming/java/src/net/i2p/client/streaming/I2PSocketEepGet.java

    refff25a r8cb503d  
    77import java.net.UnknownHostException;
    88import java.net.URL;
     9import java.util.Locale;
    910import java.util.Properties;
    1011
     
    194195                   "Cache-control: no-cache\r\n" +
    195196                   "Pragma: no-cache\r\n" +
    196                    "User-Agent: " + USER_AGENT + "\r\n" +
    197197                   "Connection: close\r\n");
     198        boolean uaOverridden = false;
    198199        if (_extraHeaders != null) {
    199200            for (String hdr : _extraHeaders) {
     201                if (hdr.toLowerCase(Locale.US).startsWith("user-agent: "))
     202                    uaOverridden = true;
    200203                buf.append(hdr).append("\r\n");
    201204            }
    202205        }
     206        if(!uaOverridden)
     207            buf.append("User-Agent: " + USER_AGENT + "\r\n");
    203208        buf.append("\r\n");
    204209        return buf.toString();
  • core/java/src/net/i2p/util/EepGet.java

    refff25a r8cb503d  
    11571157            (!path.endsWith(".gz")) && (!path.endsWith(".tgz")))
    11581158            buf.append("gzip");
    1159         buf.append("\r\nUser-Agent: " + USER_AGENT + "\r\n" +
    1160                    "Connection: close\r\n");
     1159        buf.append("\r\n");
     1160        boolean uaOverridden = false;
    11611161        if (_extraHeaders != null) {
    11621162            for (String hdr : _extraHeaders) {
     1163                if (hdr.toLowerCase(Locale.US).startsWith("user-agent: "))
     1164                    uaOverridden = true;
    11631165                buf.append(hdr).append("\r\n");
    11641166            }
    11651167        }
    1166         buf.append("\r\n");
     1168        if(!uaOverridden)
     1169            buf.append("User-Agent: " + USER_AGENT + "\r\n");
     1170        buf.append("Connection: close\r\n\r\n");
    11671171        if (post)
    11681172            buf.append(_postData);
     
    12381242     *  Add an extra header to the request.
    12391243     *  Must be called before fetch().
     1244     *  Not supported by EepHead.
     1245     *  As of 0.9.10, If name is User-Agent, this will replace the default User-Agent header.
     1246     *  Note that headers may be subsequently modified or removed in the I2PTunnel HTTP Client proxy.
    12401247     *
    12411248     *  @since 0.8.8
     
    12511258     *  Only added if the request is going through a proxy.
    12521259     *  Must be called before fetch().
     1260     *  Not supported by EepHead.
    12531261     *
    12541262     *  @since 0.8.9
  • core/java/src/net/i2p/util/PartialEepGet.java

    refff25a r8cb503d  
    66import java.net.MalformedURLException;
    77import java.net.URL;
     8import java.util.Locale;
    89
    910import net.i2p.I2PAppContext;
     
    144145
    145146        buf.append("Cache-control: no-cache\r\n" +
    146                    "Pragma: no-cache\r\n");
    147         // This will be replaced if we are going through I2PTunnelHTTPClient
    148         buf.append("User-Agent: " + USER_AGENT + "\r\n" +
     147                   "Pragma: no-cache\r\n" +
    149148                   "Accept-Encoding: \r\n" +
    150149                   "Connection: close\r\n");
     150        boolean uaOverridden = false;
    151151        if (_extraHeaders != null) {
    152152            for (String hdr : _extraHeaders) {
     153                if (hdr.toLowerCase(Locale.US).startsWith("user-agent: "))
     154                    uaOverridden = true;
    153155                buf.append(hdr).append("\r\n");
    154156            }
    155157        }
     158        // This will be replaced if we are going through I2PTunnelHTTPClient
     159        if(!uaOverridden)
     160            buf.append("User-Agent: " + USER_AGENT + "\r\n");
    156161        buf.append("\r\n");
    157162
Note: See TracChangeset for help on using the changeset viewer.