Closed frankiDotNet closed 5 years ago
Ok after trying with SharpZibLib and round about 1000 other ways of compressing the result.. :-D I logged the string before each response and I have seen that the after request delegate is getting called twice, I thought it is some kind of internal round trip, but then I logged the resulting stream as string and have seen that the second time the response stream has the compressed string already in, so the string was compressed twice. After searching through google I found an example where for each NancyHost there is created a new Bootstraper. So the following worked for me:
try
{
var hostConfig1 = new HostConfiguration()
{
UrlReservations = new UrlReservations { CreateAutomatically = true },
EnableClientCertificates = true,
RewriteLocalhost = true
};
host1 = new NancyHost(new NancyCompression(), hostConfig1, new Uri(baseAddress1));
host1.Start();
host2 = new NancyHost(new NancyCompression(), hostConfig1, new Uri(baseAddress2));
host2.Start();
}
catch (Exception ex)
{
Console.WriteLine($"Error while opening host...{ex}");
throw;
}
Console.WriteLine("Enter key to exit..");
Console.ReadLine();
return;
I have not found such example in the docs, so adding the info that each NancyHost needs an own Bootstrapper would be helpfull..
Out of curiosity, why create two hosts in one executable instead of making the port configurable and starting multiple instances? I suspect this was not an expected use case of the default Nancy host constructor.
On Mon, Nov 26, 2018, 06:20 Franki1986 <notifications@github.com wrote:
Ok after trying with SharpZibLib and round about 1000 other ways of compressing the result.. :-D I logged the string before each response and I have seen that the after request delegate is getting called twice, I thought it is some kind of internal round trip, but then I logged the resulting stream as string and have seen that the second time the response stream has the compressed string already in, so the string was compressed twice. After searching through google I found an example where for each NancyHost there is created a new Bootstraper. So the following worked for me:
try { var hostConfig1 = new HostConfiguration() { UrlReservations = new UrlReservations { CreateAutomatically = true }, EnableClientCertificates = true, RewriteLocalhost = true }; host1 = new NancyHost(new NancyCompression(), hostConfig1, new Uri(baseAddress1)); host1.Start(); host2 = new NancyHost(new NancyCompression(), hostConfig1, new Uri(baseAddress2)); host2.Start(); } catch (Exception ex) { Console.WriteLine($"Error while opening host...{ex}"); throw; } Console.WriteLine("Enter key to exit.."); Console.ReadLine(); return;
I have not found such example in the docs, so adding the info that each NancyHost needs an own Bootstrapper would be helpfull..
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/NancyFx/Nancy/issues/2944#issuecomment-441636180, or mute the thread https://github.com/notifications/unsubscribe-auth/AEEilkKmhzHN41DlVorAzhmbGwU7InfAks5uy-qhgaJpZM4YyfaK .
Do you mean create two instances by creating the host with an Uri array?
You can’t have 2 hosts on the 1 instance. Need 2 separate instances.
I am not sure if the way I am doing is wrong. If something is not right, could you please show it in an example what would be the right way?
Sorry, I realize now that my wording was unclear. I meant make the port configurable and run the executable multiple times with different ports. Though, I don't understand. Why do you want to use two ports on one machine for the same set of HTTP endpoints?
On Mon, Nov 26, 2018 at 7:40 AM Franki1986 notifications@github.com wrote:
I am not sure if the way I am doing is wrong. If something is not right, could you please show it in an example what would be the right way?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/NancyFx/Nancy/issues/2944#issuecomment-441661054, or mute the thread https://github.com/notifications/unsubscribe-auth/AEEilghaILwe1mMqLV-1ReuURsxqD1pAks5uy_1DgaJpZM4YyfaK .
-- Jonathon Koyle
I have two applications that communicate with the webservices. And the webservices can be configured in diferent ways. And probably you can define to listen on any port only in the NancyHost instance. So if one should be accessed only local the other could be accessed from anywhere
I am reporting a bug for this version:
Nancy: 1.4.5 Nancy.Hosting.Self: 1.4.1
Scenario 1, single NancyHost with two Uris:
NancyModule:
Response Body in browser:
{"id":2,"name":"Test"}
Request Headers
GET /api/test HTTP/1.1 Host: localhost:51235 Connection: keep-alive Cache-Control: max-age=0 Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8 Accept-Encoding: gzip, deflate, br Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7
Response Headers:
HTTP/1.1 200 OK Transfer-Encoding: chunked Content-Type: application/json; charset=utf-8 Content-Encoding: gzip Server: Microsoft-HTTPAPI/2.0 Date: Mon, 26 Nov 2018 07:42:02 GMT
Scenario 2 two NancyHosts with unique Uri:
string baseAddress1 = "http://localhost:51234/api/"; string baseAddress2= "http://localhost:51235/api/"; NancyHost host1; NancyHost host2; try { var hostConfig1 = new HostConfiguration() { UrlReservations = new UrlReservations { CreateAutomatically = true }, EnableClientCertificates = true, RewriteLocalhost = true }; host1 = new NancyHost(hostConfig1, new Uri(baseAddress1)); host1.Start();