public class EepPostextends EepGet
Extends EepGet for POST. Adapted from old jrandom EepPost, removed 2012 as unused. Ref: RFC 7578.
  • Field Details

    • CRLF

      private static final String CRLF
      Line ending in an HTTP header.
      See Also:
    • CRLFB

      private static final byte[] CRLFB
      The header line ending, as bytes.
    • PROP_MAX_POST_PAYLOAD_RAM

      private static final int PROP_MAX_POST_PAYLOAD_RAM
      Most of a POST body kept in memory, in bytes.
      See Also:
  • Constructor Details

    • EepPost

      public EepPost(I2PAppContext ctx, String proxyHost, int proxyPort, int numRetries, String outputFile, String url)
      Constructor for a POST session. The post body is supplied later by one of the post(Map, long, long, long) methods; fetch() is not supported.
      Parameters:
      ctx - the app context
      proxyHost - the proxy hostname, empty for no proxy
      proxyPort - the proxy port, 0 for no proxy
      numRetries - number of retries
      outputFile - file to save the response to
      url - URL to post to
  • Method Details

    • post

      public boolean post(Map<String,Object> fields, long headerTimeout, long totalTimeout, long inactivityTimeout)
      Submit an HTTP POST to the given URL (using the proxy if specified), uploading the given fields. If the field's value is a File object, then that file is uploaded, and if the field's value is a String object, the value is posted for that particular field. Multiple values for one field name is not currently supported.

      Large files will be copied to a temp file. For large String content, consider the post(File) method.

      Note: param field values must be String or File.

      Parameters:
      fields - the field names and values to submit, each value a String or a File
      headerTimeout - milliseconds to wait for the response headers of each attempt, <= 0 for none
      totalTimeout - milliseconds for the whole post including retries, <= 0 for none
      inactivityTimeout - milliseconds to wait between body bytes, <= 0 for the default
      Returns:
      true if the post succeeded
    • post

      public boolean post(String contentType, String data, long headerTimeout, long totalTimeout, long inactivityTimeout)
      In-memory, not for large POSTs.
      Parameters:
      contentType - the value for the Content-Type header
      data - the post body, must not be empty
      headerTimeout - milliseconds to wait for the response headers of each attempt, <= 0 for none
      totalTimeout - milliseconds for the whole post including retries, <= 0 for none
      inactivityTimeout - milliseconds to wait between body bytes, <= 0 for the default
      Returns:
      true if the post succeeded
    • post

      public boolean post(String contentType, byte[] data, long headerTimeout, long totalTimeout, long inactivityTimeout)
      In-memory, not for large POSTs.
      Parameters:
      contentType - the value for the Content-Type header
      data - the post body, must not be empty
      headerTimeout - milliseconds to wait for the response headers of each attempt, <= 0 for none
      totalTimeout - milliseconds for the whole post including retries, <= 0 for none
      inactivityTimeout - milliseconds to wait between body bytes, <= 0 for the default
      Returns:
      true if the post succeeded
    • post

      public boolean post(String contentType, File data, long headerTimeout, long totalTimeout, long inactivityTimeout)
      For large POSTs.
      Parameters:
      contentType - the value for the Content-Type header
      data - the post body, must be a regular file and not empty
      headerTimeout - milliseconds to wait for the response headers of each attempt, <= 0 for none
      totalTimeout - milliseconds for the whole post including retries, <= 0 for none
      inactivityTimeout - milliseconds to wait between body bytes, <= 0 for the default
      Returns:
      true if the post succeeded
    • fetch

      public boolean fetch()
      Not supported, use post() instead.
      Overrides:
      fetch in class EepGet
      Returns:
      whether the URL was retrieved; false if every attempt failed
      Throws:
      UnsupportedOperationException - always; this class posts only
    • fetch

      public boolean fetch(long fetchHeaderTimeout)
      Not supported, use post() instead.
      Overrides:
      fetch in class EepGet
      Parameters:
      fetchHeaderTimeout - timeout in ms
      Returns:
      whether the URL was retrieved; false if every attempt failed
      Throws:
      UnsupportedOperationException - always; this class posts only
    • fetch

      public boolean fetch(long fetchHeaderTimeout, long totalTimeout, long inactivityTimeout)
      Not supported, use post() instead.
      Overrides:
      fetch in class EepGet
      Parameters:
      fetchHeaderTimeout - <= 0 for none (proxy will timeout if none, none isn't recommended if no proxy) forced to totalTimeout if totalTimeout is set and this is <= 0
      totalTimeout - operation-wide deadline for the whole fetch, including retries and backoff between attempts; <= 0 for default none
      inactivityTimeout - <= 0 for default EepGet.DEFAULT_INACTIVITY_TIMEOUT (5 minutes)
      Returns:
      whether the URL was retrieved; false if every attempt failed
      Throws:
      UnsupportedOperationException - always; this class posts only
    • sendFields

      private static void sendFields(StringBuilder out, Map<String,Object> fields)
      Adapted from old jrandom EepPost.
      Parameters:
      out - the StringBuilder the urlencoded body is appended to
      fields - field names mapped to values, stringified with toString()
    • sendFields

      private static void sendFields(OutputStream out, String separator, Map<String,Object> fields) throws IOException
      Multipart Adapted from old jrandom EepPost.
      Parameters:
      out - the stream the multipart body is written to
      separator - non-null
      fields - field names mapped to values, File values sent as file parts
      Throws:
      IOException - if writing fails or a File value cannot be read
    • sendField

      private static void sendField(StringBuilder out, String field, String val)
      Adapted from old jrandom EepPost.
      Parameters:
      out - the StringBuilder the name=value pair is appended to
      field - the field name, spaces replaced with '+'
      val - the field value, spaces replaced with '+' as well
    • sendField

      private static void sendField(OutputStream out, String separator, String field, String val) throws IOException
      Multipart Adapted from old jrandom EepPost.
      Parameters:
      out - the stream the part is written to
      separator - non-null
      field - the field name, written into the content disposition
      val - the field value, written as the part body
      Throws:
      IOException - if writing to the stream fails
    • sendFile

      private static void sendFile(OutputStream out, String separator, String field, File file) throws IOException
      Multipart Adapted from old jrandom EepPost.
      Parameters:
      out - the stream the part is written to
      separator - non-null
      field - the field name, written into the content disposition
      file - the file to upload, sent as application/octet-stream
      Throws:
      IOException - if the file cannot be read or writing fails
    • getSeparator

      private String getSeparator()
      Adapted from old jrandom EepPost.
      Returns:
      a fresh random multipart boundary, base32 encoded
    • main

      public static void main(String[] args)
      Command-line entry point for EepPost. See usage() for the full option list.

      Usage: eeppost [-p 127.0.0.1:4444 | -c] [-n #retries] [-o outputFile] [-s key=value] | [-f key=file] url

      At least one -s (string field) or -f (file field) is required. All timeouts are in seconds: -t is the inactivity timeout, -v the header timeout, and -w the total timeout, which is unlimited by default.

      Parameters:
      args - the options and URL as described by usage()
    • usage

      static String usage()
      Usage text for the command-line entry point. Every option accepted by main(String[]) must appear here, with the defaults main() actually uses.
      Returns:
      the help text