]
Steven Hawkins updated TEIID-5942:
----------------------------------
Original Estimate: 2 hours, 30 minutes
Remaining Estimate: 2 hours, 30 minutes
Story Points: 0.5
Sprint: DV Sprint 62
OData request fails when Host header specifies also port
--------------------------------------------------------
Key: TEIID-5942
URL:
https://issues.redhat.com/browse/TEIID-5942
Project: Teiid
Issue Type: Bug
Components: OData
Reporter: Steven Hawkins
Assignee: Steven Hawkins
Priority: Blocker
Fix For: 14.0, 13.0.3, 13.1.1
Original Estimate: 2 hours, 30 minutes
Remaining Estimate: 2 hours, 30 minutes
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:
{code}
$ curl -s -k
https://host/odata/Source/SimpleTableView | jq
'."(a)odata.context"'
"https://host:443/odata/Source/$metadata#SimpleTableView"
{code}
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:
{code}
$ curl -vs -k
https://host/odata/Source/SimpleTableView 2>&1 | grep
'Host:'
> Host: host
{code}
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
{code}
Host: host:443
{code}
This is in fact in line with [RFC
2616|https://tools.ietf.org/html/rfc2616#section-14.23]
which states
{quote}
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
{quote}
Requests with such a header will fail in the vdb pod with the following exception:
{code}
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
{code}
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.