<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>SLM Application: Unable to specify custom HTTP host header.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/91853/slm-application-unable-to-specify-custom-http-host-header</link><description>Currently it is impossible to specify your own HTTP host header in the SLM-application nRFConnectSDK. The host header is appended automatically by Zephyr by using the host-parameter on the http_request object. Specifying your own Host: header through</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 14 Sep 2022 14:26:17 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/91853/slm-application-unable-to-specify-custom-http-host-header" /><item><title>RE: SLM Application: Unable to specify custom HTTP host header.</title><link>https://devzone.nordicsemi.com/thread/386224?ContentTypeID=1</link><pubDate>Wed, 14 Sep 2022 14:26:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:08d51bef-dc50-47f8-b2c8-9e85234bf123</guid><dc:creator>Ivan Herrera</dc:creator><description>&lt;p&gt;Hi Hakon!&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks for your reply. We will resort to your solution.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SLM Application: Unable to specify custom HTTP host header.</title><link>https://devzone.nordicsemi.com/thread/385757?ContentTypeID=1</link><pubDate>Mon, 12 Sep 2022 13:34:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:de68cfe8-ab70-46cf-aa19-39a3a25dd796</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Ivan Herrera"]Correct, we want to replace&amp;nbsp;the default Host header but not in the https_client example. In the SLM-application (Serial LTE Modem[/quote]
&lt;p&gt;Yes, I took the https_client sample as it states &amp;quot;host:&amp;quot; in plain text.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user="Ivan Herrera"]&lt;p&gt;Assume the following situation:&lt;/p&gt;
&lt;p&gt;There is a HTTP-server running at IP 127.0.0.1, and it is hosting the following domains:&lt;/p&gt;
&lt;p&gt;- test1.nordicsemi.com&lt;br /&gt;- test2.nordicsemi.com&lt;/p&gt;
&lt;p&gt;The webserver uses the &amp;quot;Host: &amp;lt;hostname&amp;gt;&amp;quot; HTTP-header to differentiate which website to serve. Our device wants to send requests to both domains. Hence we connect to the webserver by the following command:&lt;/p&gt;
&lt;p&gt;&lt;span&gt;-&amp;nbsp;&lt;/span&gt;&lt;span&gt;AT#XHTTPCCON=1,&amp;quot;127.0.0.1&amp;quot;,80&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;There is now a connection open with the webserver. We want to send two requests, one to test1.nordicsemi.com and one to test2.nordicsemi.com&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;We use the following command to specify a request to test1.nordicsemi.com:&lt;/span&gt;&lt;/p&gt;[/quote]
&lt;p&gt;You&amp;#39;re working around not having DNS.&lt;/p&gt;
&lt;p&gt;Wouldn&amp;#39;t the workaround be that you provide a valid DNS?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Have you tried setting a secondary DNS manually, via this function call?&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrfxlib/blob/v2.1.0-rc1/nrf_modem/include/nrf_socket.h#L809"&gt;https://github.com/nrfconnect/sdk-nrfxlib/blob/v2.1.0-rc1/nrf_modem/include/nrf_socket.h#L809&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s an example implementation:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;struct nrf_in_addr dns;
int err = nrf_inet_pton(NRF_AF_INET, &amp;quot;8.8.8.8&amp;quot;, &amp;amp;dns);
if (err != 1) {
    LOG_ERR(&amp;quot;Failed to convert custom DNS address to %s, err %d&amp;quot;, &amp;quot;8.8.8.8&amp;quot;, errno);
    return ;
}
err = nrf_setdnsaddr(NRF_AF_INET, &amp;amp;dns);
if (err) {
    LOG_ERR(&amp;quot;Failed to set custom DNS address to %s, err %d&amp;quot;, &amp;quot;8.8.8.8&amp;quot;, errno);
    return ;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SLM Application: Unable to specify custom HTTP host header.</title><link>https://devzone.nordicsemi.com/thread/385734?ContentTypeID=1</link><pubDate>Mon, 12 Sep 2022 12:19:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:10de1588-43e5-48c3-8505-6f8e043882d2</guid><dc:creator>Ivan Herrera</dc:creator><description>&lt;p&gt;Correct, we want to replace&amp;nbsp;the default Host header but not in the https_client example. In the SLM-application (Serial LTE Modem &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/applications/serial_lte_modem/README.html)."&gt;https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/applications/serial_lte_modem/README.html).&amp;nbsp;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You implemented the following commands:&lt;/p&gt;
&lt;p&gt;-&amp;nbsp;AT#XHTTPCCON=&amp;lt;op&amp;gt;[,&amp;lt;host&amp;gt;,&amp;lt;port&amp;gt;[,&amp;lt;sec_tag&amp;gt;]]&amp;nbsp;&lt;/p&gt;
&lt;p&gt;-&amp;nbsp;AT#XHTTPCREQ=&amp;lt;method&amp;gt;,&amp;lt;resource&amp;gt;[,&amp;lt;headers&amp;gt;[,&amp;lt;content_type&amp;gt;,&amp;lt;content_length&amp;gt;[,&amp;lt;chunked_transfer&amp;gt;]]]&lt;/p&gt;
&lt;p&gt;Assume the following situation:&lt;/p&gt;
&lt;p&gt;There is a HTTP-server running at IP 127.0.0.1, and it is hosting the following domains:&lt;/p&gt;
&lt;p&gt;- test1.nordicsemi.com&lt;br /&gt;- test2.nordicsemi.com&lt;/p&gt;
&lt;p&gt;The webserver uses the &amp;quot;Host: &amp;lt;hostname&amp;gt;&amp;quot; HTTP-header to differentiate which website to serve. Our device wants to send requests to both domains. Hence we connect to the webserver by the following command:&lt;/p&gt;
&lt;p&gt;&lt;span&gt;-&amp;nbsp;&lt;/span&gt;&lt;span&gt;AT#XHTTPCCON=1,&amp;quot;127.0.0.1&amp;quot;,80&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;There is now a connection open with the webserver. We want to send two requests, one to test1.nordicsemi.com and one to test2.nordicsemi.com&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;We use the following command to specify a request to test1.nordicsemi.com:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;AT#XHTTPCREQ=GET,&amp;quot;/api/version&amp;quot;,&amp;quot;Host: test1.nordicsemi.com\r\n&amp;quot;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;What we expect to happen is for the SLM to send the following HTTP request:&lt;/span&gt;&lt;/p&gt;
&lt;pre class="result notranslate"&gt;GET /api/version HTTP/1.1
Host: &lt;span&gt;test1.nordicsemi.com&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;span&gt;What actually happens, is that the Nordic Serial LTE Modem application assumes that&amp;nbsp;the IP we provided in XHTTPCON is also the hostname we want to provide in the HTTP-header. The following (invalid) request gets sent out:&lt;/span&gt;&lt;/p&gt;
&lt;pre class="result notranslate"&gt;GET /api/version HTTP/1.1&lt;br /&gt;Host: 127.0.0.1
Host: &lt;span&gt;test1.nordicsemi.com&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;span&gt;Naturally, the HTTP-server responds with status code 400: Invalid request, as there is a duplicate host header in the HTTP-request, which is illegal. We propose that the SLM does not provide its own host-header when the user specifies one themselves.&lt;/span&gt;&lt;/p&gt;
&lt;pre class="result notranslate"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/pre&gt;
&lt;pre class="result notranslate"&gt;&lt;/pre&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SLM Application: Unable to specify custom HTTP host header.</title><link>https://devzone.nordicsemi.com/thread/385728?ContentTypeID=1</link><pubDate>Mon, 12 Sep 2022 12:04:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ffbc18b7-1fbf-4158-b241-c749219e4c20</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Just to ensure that I understand the scenario fully, it is the &amp;quot;Host: ...&amp;quot; string in the http-template that you want to replace?&lt;/p&gt;
&lt;p&gt;Ie. similar to this one?&amp;nbsp;&lt;a href="https://github.com/nrfconnect/sdk-nrf/blob/main/samples/nrf9160/https_client/src/main.c#L22"&gt;https://github.com/nrfconnect/sdk-nrf/blob/main/samples/nrf9160/https_client/src/main.c#L22&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If yes, this is a bit of a strange scenario, as it seems to&amp;nbsp;me that you&amp;#39;re&amp;nbsp;requesting a http proxy functionality.&lt;/p&gt;
&lt;p&gt;At this point, the DNS (ie. getaddrinfo()) has already been run, and you&amp;#39;re connected to the server you&amp;#39;re communicating with.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Or is the root problem here the getaddrinfo() call, which is called through slm_util.c::util_resolve_host() ?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>