Skip to content

Commit

Permalink
Add default Accept header and port number to Host (#213)
Browse files Browse the repository at this point in the history
* Add default Accept header and port number to Host

Kitura-net adds a default Accept header and appends port number to host name if
non-default ports(443/80) are used. In order to maintain parity default Accept
header is added and port name is appended if non default port is used.

* Add default Accept header and port number to Host

Kitura-net adds a default Accept header and appends port number to host name if
non-default ports(443/80) are used. In order to maintain parity default Accept
header is added and port name is appended if non default port is used.
  • Loading branch information
harish1992 authored and Pushkar N Kulkarni committed Jul 22, 2019
1 parent 315aca7 commit dfdbff2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Sources/KituraNet/ClientRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,16 @@ public class ClientRequest {
}

let hostName = URL(string: percentEncodedURL)?.host ?? "" //TODO: what could be the failure path here
let portNumber = URL(string: percentEncodedURL)?.port ?? 8080
if self.headers["Host"] == nil {
self.headers["Host"] = hostName
let isNotDefaultPort = (portNumber != 443 && portNumber != 80) //Check whether port is not 443/80
self.headers["Host"] = hostName + (isNotDefaultPort ? (":" + String(portNumber)) : "")
}

// To keep Kitura-NIO's behaviour similar to Kitura-net, add the Accept header with default value '*/*'.
// Note:libcurl adds default value for Accept header for Kitura-net
if self.headers["Accept"] == nil && self.headers["accept"] == nil {
self.headers["Accept"] = "*/*"
}

self.headers["User-Agent"] = "Kitura"
Expand Down

0 comments on commit dfdbff2

Please sign in to comment.