Uploaded image for project: 'HttpComponents HttpClient'
  1. HttpComponents HttpClient
  2. HTTPCLIENT-1860

Simplify pre-status-line garbage rejection config

    XMLWordPrintableJSON

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Minor
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None

      Description

      I'm building HttpClient via HttpClientBuilder, version is httpclient-4.5.3.jar.

      By default there is no limit on the amount of garbage before status line (see DefaultHttpResponseParser#reject). I'd like to set one: no more than X lines.
      The documentation tells I'm to provide custom DefaultHttpResponseParser. So far so good: I'm just to override one method. But to plug my DefaultHttpResponseParser in I have to do a lot of things. I have to instantiate/configure/provide (hereinafter "deal with") a handful of other objects. Specifically:

      • I have to implement my HttpMessageParserFactory that returns my DefaultHttpResponseParser, for that I also have to provide LineParser and HttpResponseFactory.
      • then I create ManagedHttpClientConnectionFactory that returns my HttpMessageParserFactory
      • then I create PoolingHttpClientConnectionManager where I put ManagedHttpClientConnectionFactory. And for that I also have to deal with Registry<ConnectionSocketFactory>, PublicSuffixMatcher, HostnameVerifier, SSLConnectionSocketFactory, SchemePortResolver, DnsResolver; plus timeToLive config property
      • also I have not to forget to set the same publicSuffixMatcher to HttpClientBuilder, as it's used not only for ConnectionManager configuration

      The full required code is attached (LeadingGarbageLimiter.java).

      Not only that's hard, but having to deal with so much of stuff my code becomes more fragile to potential API changes.

      As an API client I'd very much appreciate some single-line config for such simple tweak as the limit we're talking about.
      I'd propose to add int maxGarbageBeforeStatusLine to MessageConstraints, it naturally fits there along to the existing maxLineLength and maxHeaderCount settings.
      And then use the new setting in DefaultHttpResponseParser.
      Then all a client would have to do is HttpClientBuilder.create().setMaxGarbageBeforeStatusLine(X).

        Attachments

        1. LeadingGarbageLimiter.java
          3 kB
          Artem Nakonechnyy

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              anakonechny Artem Nakonechnyy
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: