<p dir="auto">Like the layouts and pieces in Rails, I want a method to reuse the code. Currently the webview tag can only display a whole html page; hence I should always write duplicated html header tags and so on. Sharing on the global javascript objects among them directly (since they may in the same page it's redundant to have another scheme handle the sharing problem) could also save a lot of codes. Or is there any way to customize an html tag so that I can implement what I need.</p>
<p dir="auto">As I understand things the net module is supposed to follow the Node API as closely as possible, from <a href="https://github.com/electron/electron/blob/master/docs/api/net.md">net.md</a></p>
<blockquote>
<p dir="auto">The net module API has been specifically designed to mimic, as closely as possible, the familiar Node.js API. The API components including classes, methods, properties and event names are similar to those commonly used in Node.js.</p>
</blockquote>
<p dir="auto">The net module version of <code class="notranslate">IncommingMessage</code>, however, <a href="https://github.com/electron/electron/blob/master/lib/browser/api/net.js#L42">returns a different structure</a> for its header collection than its Node counterpart. Where Node returns a simple object like <code class="notranslate">{ "Content-Type": "foo", ... }</code> the net module returns an object where each value is an array containing any duplicate headers: <code class="notranslate">{ "Content-Type": [ "foo" ], ...}</code></p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/634063/20796414/490139ba-b7d6-11e6-920f-d24f8e7cc036.png"><img width="356" alt="screen shot 2016-12-01 at 14 55 49" src="https://cloud.githubusercontent.com/assets/634063/20796414/490139ba-b7d6-11e6-920f-d24f8e7cc036.png" style="max-width: 100%;"></a></p>
<p dir="auto">So the net module returns duplicate headers as an array whereas Node will concat duplicate headers into a single string value (comma separated list) if the header is defined as a list in the HTTP specification.</p>
<p dir="auto">From <a href="https://nodejs.org/api/http.html#http_message_headers" rel="nofollow">the Node docs</a></p>
<blockquote>
<p dir="auto">Duplicates in raw headers are handled in the following ways, depending on the header name:</p>
<p dir="auto">Duplicates of age, authorization, content-length, content-type, etag, expires, from, host, if-modified-since, if-unmodified-since, last-modified, location, max-forwards, proxy-authorization, referer, retry-after, or user-agent are discarded.</p>
<p dir="auto">set-cookie is always an array. Duplicates are added to the array.</p>
<p dir="auto">For all other headers, the values are joined together with ', '.</p>
</blockquote>
<h3 dir="auto">Expected behavior</h3>
<p dir="auto">Duplicate HTTP response headers should be joined together if allowed by the HTTP specification or else discarded.</p>
<h3 dir="auto">Actual behavior</h3>
<p dir="auto">Headers are returned in an array regardless of duplicates.</p>
<h3 dir="auto">Proposed solution</h3>
<p dir="auto">Node has already solved this problem once, see <a href="https://github.com/nodejs/node/blob/8264a2225628cbc32116f83a079f6024786988ab/lib/_http_incoming.js#L134-L180">_http_incoming.js#L134-L180</a>. Although the method is exposed on the <code class="notranslate">IncommingMessage</code> prototype it's an undocumented method which is subject to change so using it directly is probably #dangerzone. Since the licenses of electron and node seem compatible I propose borrowing that code and adapting it for use in electron.</p>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/kevinsawicki/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/kevinsawicki">@kevinsawicki</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/joshaber/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/joshaber">@joshaber</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/shiftkey/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/shiftkey">@shiftkey</a></p>