public class EepHeadextends EepGet
This is a quick hack to get a working EepHead, primarily for the following usage:
EepHead foo = new EepHead(...);
if (foo.fetch()) {
    String lastmod = foo.getLastModified();
    if (lastmod != null) {
        parse the string...
        ...
    }
}
Other use cases (command line, listeners, etc...) lightly- or un-tested. Note that this follows redirects! This may not be what you want or expect.

Writing from scratch rather than extending EepGet would maybe have been less bloated memory-wise. This way gets us redirect handling, among other benefits.

  • Field Details

    • _dummyStream

      private static final OutputStream _dummyStream
      EepGet needs either a non-null file or a stream... shouldn't actually be written to...
  • Constructor Details

    • EepHead

      public EepHead(I2PAppContext ctx, String proxyHost, int proxyPort, int numRetries, String url)
      Create a new EepHead to fetch HTTP response headers from the given URL.
      Parameters:
      ctx - I2P app context
      proxyHost - hostname of the eepproxy to fetch through; empty for no proxy
      proxyPort - eepproxy port, 0 when no proxy is used
      numRetries - number of retries on failure
      url - absolute URL to send the HEAD request to
  • Method Details

    • main

      public static void main(String[] args)
      CLI entry point: fetch and display HTTP response headers for a URL. Usage: EepHead [-p 127.0.0.1:4444] [-n #retries] url.
      Parameters:
      args - the command line arguments, with options set by -p host:port, -n retries, -t seconds, -u user and -x password, followed by the URL whose headers are to be fetched
    • printResponse

      private static void printResponse(EepHead get, String url)
      Print all available response headers.
      Parameters:
      get - the EepHead instance after fetch
      url - the original request URL
    • guessServer

      private static String guessServer(String server, String cc, String cl, String lm, String ar, String et, String xf, String cto)
      Try to identify the server software from the response headers. Uses known header fingerprints when the Server header is absent.
      Parameters:
      server - Server header value (may be null)
      cc - Cache-Control header value
      cl - Content-Length as string
      lm - Last-Modified header value
      ar - Accept-Ranges header value
      et - ETag header value
      xf - X-Frame-Options header value
      cto - X-Content-Type-Options header value
      Returns:
      the identified server name, or "unknown"
    • usage

      private static String usage()
      Return the command-line usage text for eephead.
      Returns:
      CLI usage string
    • doFetch

      protected void doFetch(SocketTimeout timeout) throws IOException
      Read the response headers and notify listeners.
      Overrides:
      doFetch in class EepGet
      Parameters:
      timeout - may be null as of 0.9.49
      Throws:
      IOException - on IO error
    • shouldReadBody

      protected boolean shouldReadBody()
      Should we read the body of the response?
      Overrides:
      shouldReadBody in class EepGet
      Returns:
      false always
    • getRequest

      protected String getRequest() throws IOException
      Build the HTTP HEAD request, including headers for Host, User-Agent, and proxy auth.
      Overrides:
      getRequest in class EepGet
      Returns:
      the full HTTP 1.1 request string
      Throws:
      IOException - on bad URL
    • getContentLength

      public long getContentLength()
      We don't decrement the variable (unlike in EepGet), so this is valid.
      Returns:
      the Content-Length reported by the server, in bytes