Uploaded image for project: 'Teiid'
  1. Teiid
  2. TEIID-5942

OData request fails when Host header specifies also port

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Blocker
    • 14.0, 13.0.3, 13.1.1
    • None
    • OData
    • None
    • DV Sprint 62
    • 0.5
    • Hide
      curl -ks https://<route-to-vdb>/odata/$metadata -H 'Host: <route-to-vdb>:443'
      
      Show
      curl -ks https: //<route-to-vdb>/odata/$metadata -H 'Host: <route-to-vdb>:443'

    Description

      TLDR: using the URLs returned in odata responses for new requests in apache http client causes 406 in the server pod because it tries to add the port twice to the url


      The current implementation of odata endpoint always adds the port to the returned links (such as context or nextLink), even when using the default port and not specifying it in the request:

      $ curl -s -k https://host/odata/Source/SimpleTableView  | jq '."@odata.context"'             
      "https://host:443/odata/Source/$metadata#SimpleTableView"
      

      This is ok, but will be important for triggering the issue later.

      Tools such as curl or web browsers strip the port from the hostname before they set it in the Host header on the HTTP request:

      $ curl -vs -k https://host/odata/Source/SimpleTableView 2>&1  | grep 'Host:'
      > Host: host
      

      However, the Apache HTTP client java client (also used by the olingo odata 4 client) does not strip the port, resulting in Host header such as

      Host: host:443
      

      This is in fact in line with RFC 2616 which states

      The Host request-header field specifies the Internet host and port
      number of the resource being requested, as obtained from the original
      URI given by the user or referring resource

      Requests with such a header will fail in the vdb pod with the following exception:

      Caused by: java.lang.RuntimeException: Unable to create URI: https://host:443:443/odata/Source/SimpleTableView
      	at org.teiid.olingo.web.ProxyHttpServletRequest.<init>(ProxyHttpServletRequest.java:85) ~[teiid-olingo-13.1.1.fuse-jdk11-800015-redhat-00001.jar!/:13.1.1.fuse-jdk11-800015-redhat-00001]
      	at org.teiid.spring.odata.SpringODataFilter.handleProxiedRequest(SpringODataFilter.java:218) ~[spring-odata-1.4.1.fuse-jdk11-800012-redhat-00001.jar!/:1.4.1.fuse-jdk11-800012-redhat-00001]
      	at org.teiid.spring.odata.SpringODataFilter.preHandle(SpringODataFilter.java:73) ~[spring-odata-1.4.1.fuse-jdk11-800012-redhat-00001.jar!/:1.4.1.fuse-jdk11-800012-redhat-00001]
      	at org.springframework.web.servlet.HandlerExecutionChain.applyPreHandle(HandlerExecutionChain.java:136) ~[spring-webmvc-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
      	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1034) ~[spring-webmvc-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
      	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) ~[spring-webmvc-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
      	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005) ~[spring-webmvc-5.1.8.RELEASE.jar!/:5.1.8.RELEASE]
      	... 66 common frames omitted
      Caused by: java.net.MalformedURLException: Error at index 3 in: "443:443"
      	at java.base/java.net.URL.<init>(URL.java:679) ~[na:na]
      	at java.base/java.net.URL.<init>(URL.java:541) ~[na:na]
      	at java.base/java.net.URL.<init>(URL.java:488) ~[na:na]
      	at org.teiid.olingo.web.ProxyHttpServletRequest.<init>(ProxyHttpServletRequest.java:83) ~[teiid-olingo-13.1.1.fuse-jdk11-800015-redhat-00001.jar!/:13.1.1.fuse-jdk11-800015-redhat-00001]
      	... 72 common frames omitted
      

      Notice 443:443, it appears the backend is trying to add the port even though it's already there, which makes the resulting URL invalid.

      Attachments

        Issue Links

          Activity

            People

              rhn-engineering-shawkins Steven Hawkins
              rhn-engineering-shawkins Steven Hawkins
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 2 hours, 30 minutes
                  2h 30m
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 2 hours, 30 minutes
                  2h 30m