Project

General

Profile

Bug #9997

Apache HttpClient limitations when used via LegacySocketLibrary

Added by Constantin Asofiei about 1 year ago. Updated about 1 year ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
Due date:
% Done:

0%

billable:
No
vendor_id:
GCD
case_num:
version_reported:
version_resolved:
reviewer:
production:
No
env_name:
topics:

History

#2 Updated by Constantin Asofiei about 1 year ago

In FWD, the implementation of OpenEdge.Net.HTTP.Lib.ABLSockets.ABLSocketLibrary uses Apache HttpClient library.

In this library, some headers are not allowed (or emitted also by the HttpClient); see this test for Content-Length and Transfer-Encoding:

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.EntityBuilder;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.HttpClientBuilder;

public class ReqTest
{
   public static void main(String[] args) throws IOException, InterruptedException {
      String file = "abcdef";
      org.apache.http.client.methods.RequestBuilder requestBuilder = org.apache.http.client.methods.RequestBuilder
               .create("POST").setUri("https://httpbin.org/anything");
      requestBuilder.addHeader("Content-Type", "application/pdf");
      requestBuilder.addHeader("Authorization", "Token token=xyz");
      // requestBuilder.addHeader("Transfer-Encoding", "chunked");
      // requestBuilder.addHeader("Content-Length", String.valueOf(file.length()));
      HttpEntity httpEntity = EntityBuilder.create().setText(file).build();
      requestBuilder.setEntity(httpEntity);

      HttpUriRequest request = requestBuilder.build();
      HttpClient client = HttpClientBuilder.create().build();
      HttpResponse response = client.execute(request);
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      InputStream is = response.getEntity().getContent();
      long len = response.getEntity().getContentLength();
      for (int i = 0 ; i < len; i++)
      {
         bos.write(is.read());
      }
      System.out.println(new String(bos.toByteArray()));
      System.out.println();
  }
}

In #9990 (trunk rev 15913), there were changes to:
  • log any IO errors during the HTTP request execution
  • do not set the Context-Length or Transfer-Encoding to the actual HTTP request for the Apache HttpClient call

Sergey found that some request are 'forbidden' to be set (and can't be controlled programmatically) - see https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_request_header

What we need to investigate is:
  • what other headers can not be set for a HTTP Request in FWD (even if 4GL allows it), as is assumed to be calculated/set by the HttpClient library
  • what happens in 4GL if the http request 'breaks' - previously we were ignoring these IOException's; test:
    • set the Content-Length twice in the request or other 'forbidden' headers
    • terminate (if possible) the network connection between the caller and the target server, to trigger a kind of IOException

#3 Updated by Sergey Ivanovskiy about 1 year ago

Constantin, I just linked https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_request_header to this issue because this is a similar issue but for the browser user agent.

Also available in: Atom PDF