[go-nuts] Go API receive calls twice when hit through browser
Team, Hi all, hope you are doing good. I've made a small poc api on my windows 10 enterprise machine ``` func main() { srv := &http.Server{Addr: ":8000", Handler: http.HandlerFunc(handle)} log.Fatal(srv.ListenAndServeTLS("certificate.crt", "certificate.key")) } func handle(w http.ResponseWriter, r *http.Request) { // Log the request protocol log.Printf("Got connection: %s", r.Proto) // Send a message back to the client w.Write([]byte("Hello")) } ``` The moment I call this api using different browsers(IE/Chrome)(https://localhost:8000) or curl request I receive these kind of outputs: 1. In browser I receive "Hello" which is correct 2. In golang console prompt I get this log twice: Got connection: HTTP/2.0 Without TLS: 3. But, while making a curl request I get this log & only once: What is the difference between point 2 & 3. I've tried both tls and non tls version with browsers but in both the cases logs are coming twice. I don't know why this favicon.ico call is going. Am I missing something here. Please help. Thank you -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/216a565e-5fae-4e41-b5fb-7af3ff735fc3n%40googlegroups.com.
[go-nuts] Go API receive calls twice when hit through browser
Team, Hi all, hope you are doing good. I've made a hosted a small api on my windows 10 enterprise machine: ``` func main() { srv := &http.Server{Addr: ":8000", Handler: http.HandlerFunc(handle)} log.Fatal(srv.ListenAndServeTLS("certificate.crt", "certificate.key")) } func handle(w http.ResponseWriter, r *http.Request) { // Log the request protocol log.Printf("Got connection: %s", r.Proto) // Send a message back to the client w.Write([]byte("Hello")) } ``` The moment I call this api using different browsers(IE/Chrome)( https://localhost:8000) or curl request I receive these kind of outputs: 1. In browser I receive "Hello" which is correct 2. In golang console prompt I get this log twice: With TLS: [image: Capture.PNG] Without TLS: [image: Capture.PNG] [image: Capture.PNG] 3. But, while making a curl request I get this log & only once: [image: Capture.PNG] What is the difference between point 2 & 3. I've tried both tls and non tls version with browsers but in both the cases logs are coming twice. I don't know why this favicon.ico call is going. Am I missing something here. Please help. Thank you -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/b57283c8-8cc8-42ce-aa4a-88527dedf39an%40googlegroups.com.
Re: [go-nuts] Re: Go API receive calls twice when hit through browser
Thank you for the reply. Is there anyway to stop it completely or its the default behavior of all the browsers. It is an api and not any web page due to which adding a meta tag is not possible i think so. I've checked on google, and people are just returning a 200 status, when browser ask for favicon, in case of api's so that at least error should not return. On Friday, 25 September 2020 at 23:16:55 UTC+5:30 iko...@gmail.com wrote: > The browser tries to put a nice icon to the side of the link. Usually this > can be accomplished with a meta tag, but the browser also tries the > well-known location favicon.ico to retrieve it if there is no meta-tag. > That's why you see two requests. > > *Joop Kiefte* - Chat @ Spike > <https://spikenow.com/r/a/?ref=spike-organic-signature&_ts=p7hpq> [image: > p7hpq] > > On September 25, 2020 at 17:34 GMT, gaurav wrote: > > > First request must be OPTION and second must be GET/ POST , This is > default browser behaviour. > > On Friday, 25 September 2020 at 15:22:27 UTC+5:30 smartaq...@gmail.com > wrote: > >> Team, >> >> Hi all, hope you are doing good. >> >> I've made a hosted a small api on my windows 10 enterprise machine: >> >> ``` >> func main() { >> srv := &http.Server{Addr: ":8000", Handler: http.HandlerFunc(handle)} >>log.Fatal(srv.ListenAndServeTLS("certificate.crt", "certificate.key")) >> } >> >> func handle(w http.ResponseWriter, r *http.Request) { >> // Log the request protocol >> log.Printf("Got connection: %s", r.Proto) >> >>// Send a message back to the client >> w.Write([]byte("Hello")) >> } >> ``` >> The moment I call this api using different browsers(IE/Chrome)( >> https://localhost:8000) or curl request I receive these kind of outputs: >> >>1. In browser I receive "Hello" which is correct >>2. In golang console prompt I get this log twice: >>With TLS: >>[image: Capture.PNG] >>Without TLS: >>[image: Capture.PNG] >>[image: Capture.PNG] >> >>3. But, while making a curl request I get this log & only once: >>[image: Capture.PNG] >> >> What is the difference between point 2 & 3. I've tried both tls and non >> tls version with browsers but in both the cases logs are coming twice. I >> don't know why this favicon.ico call is going. >> >> Am I missing something here. Please help. Thank you >> > -- > > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/7da5a20a-1661-4b1d-ac5b-074a12208622n%40googlegroups.com > > <https://groups.google.com/d/msgid/golang-nuts/7da5a20a-1661-4b1d-ac5b-074a12208622n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/9f72de79-02eb-47aa-b1c0-5a6be31157c7n%40googlegroups.com.
Re: [go-nuts] Re: Go API receive calls twice when hit through browser
Thanks a lot. It is working now. After giving the API link it is making the request to the specified one only. Thank you for the help. On Sunday, 27 September 2020 at 22:45:01 UTC+5:30 iko...@gmail.com wrote: > mind: there are more well-known locations, they are just not as common as > the favicon call, so you might just want to be specific on where you expect > your API calls and only listen on that. > > *Joop Kiefte* - Chat @ Spike > <https://spikenow.com/r/a/?ref=spike-organic-signature&_ts=pb5kd> > [image: pb5kd] > > On September 27, 2020 at 17:13 GMT, Joop Kiefte wrote: > > > probably the best solution is to use the handlers and not listen on any > other link than your API links, then the favicon request won't hit your > service. You don't even really have to return a 200, just make sure you > don't answer to favicon.ico requests the very least. > > *Joop Kiefte* - Chat @ Spike > <https://spikenow.com/r/a/?ref=spike-organic-signature&_ts=pb5j9> [image: > pb5j9] > > On September 27, 2020 at 16:28 GMT, smartaq wrote: > > > Thank you for the reply. Is there anyway to stop it completely or its the > default behavior of all the browsers. It is an api and not any web page due > to which adding a meta tag is not possible i think so. > > I've checked on google, and people are just returning a 200 status, when > browser ask for favicon, in case of api's so that at least error should not > return. > > On Friday, 25 September 2020 at 23:16:55 UTC+5:30 iko...@gmail.com wrote: > >> The browser tries to put a nice icon to the side of the link. Usually >> this can be accomplished with a meta tag, but the browser also tries the >> well-known location favicon.ico to retrieve it if there is no meta-tag. >> That's why you see two requests. >> >> *Joop Kiefte* - Chat @ Spike >> <https://spikenow.com/r/a/?ref=spike-organic-signature&_ts=p7hpq> [image: >> p7hpq] >> >> On September 25, 2020 at 17:34 GMT, gaurav wrote: >> >> >> First request must be OPTION and second must be GET/ POST , This is >> default browser behaviour. >> >> On Friday, 25 September 2020 at 15:22:27 UTC+5:30 smartaq...@gmail.com >> wrote: >> >>> Team, >>> >>> Hi all, hope you are doing good. >>> >>> I've made a hosted a small api on my windows 10 enterprise machine: >>> >>> ``` >>> func main() { >>> srv := &http.Server{Addr: ":8000", Handler: http.HandlerFunc(handle)} >>>log.Fatal(srv.ListenAndServeTLS("certificate.crt", "certificate.key")) >>> } >>> >>> func handle(w http.ResponseWriter, r *http.Request) { >>> // Log the request protocol >>> log.Printf("Got connection: %s", r.Proto) >>> >>>// Send a message back to the client >>> w.Write([]byte("Hello")) >>> } >>> ``` >>> The moment I call this api using different browsers(IE/Chrome)( >>> https://localhost:8000) or curl request I receive these kind of outputs: >>> >>>1. In browser I receive "Hello" which is correct >>>2. In golang console prompt I get this log twice: >>>With TLS: >>>[image: Capture.PNG] >>>Without TLS: >>>[image: Capture.PNG] >>>[image: Capture.PNG] >>> >>>3. But, while making a curl request I get this log & only once: >>>[image: Capture.PNG] >>> >>> What is the difference between point 2 & 3. I've tried both tls and non >>> tls version with browsers but in both the cases logs are coming twice. I >>> don't know why this favicon.ico call is going. >>> >>> Am I missing something here. Please help. Thank you >>> >> -- >> >> You received this message because you are subscribed to the Google Groups >> "golang-nuts" group. >> >> To unsubscribe from this group and stop receiving emails from it, send an >> email to golang-nuts...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/golang-nuts/7da5a20a-1661-4b1d-ac5b-074a12208622n%40googlegroups.com >> >> <https://groups.google.com/d/msgid/golang-nuts/7da5a20a-1661-4b1d-ac5b-074a12208622n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> >> -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/9f72de79-02eb-47aa-b1c0-5a6be31157c7n%40googlegroups.com > > <https://groups.google.com/d/msgid/golang-nuts/9f72de79-02eb-47aa-b1c0-5a6be31157c7n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/bd7d9db0-fee5-461b-ad5b-08a146fa2ca3n%40googlegroups.com.
[go-nuts] http server unable to authorize other CA authorities on windows
Team, Hi all, hope you're doing well. I have hosted a small api on windows 10 machine which I'm using as a webhook receiver. The CA authority of webhook sender is different from the CA authority of the golang api. Code of API is:- --- func main() { caCertPool := x509.NewCertPool() caCert2, _ := ioutil.ReadFile(" .pem ") caCertPool.AppendCertsFromPEM(caCert2) tlsConfig := &tls.Config{ RootCAs:caCertPool, InsecureSkipVerify: false,//tried with true and false both ClientCAs: caCertPool, //tried by giving and removing this property as well. } tlsConfig.BuildNameToCertificate() srv := &http.Server{Addr: ":443", TLSConfig: tlsConfig, Handler: http.HandlerFunc(handle)} log.Fatal(srv.ListenAndServeTLS("certificate.crt", "certificate.key")) } func handle(w http.ResponseWriter, r *http.Request) { // Log the request protocol log.Printf("Got connection: %s", r.Proto) // Send a message back to the client w.Write([]byte("Hello")) } -- *".pem" * :- this has the chain of all CA including webhook sender *"certificate.crt "* :- this certificate has complete root chain of other CA Still whenever I'm trying to make a call from webhook sender(github) to my api a tls handshake error occurs. Error at webhook sender side:- *Peer certificate cannot be authenticated with given CA certificates webhook* Error at webhook receiver side:- *TLS handshake error* The moment I've used another certificate in the method *ListenAndServeTLS, *created with the CA authority same as that of webhook sender, everything worked fine. In production, we're not allowed to make any certificate in that CA. Can anyone suggest me the procedure of trusting other CA's in case of windows machines with golang. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/5e0c5369-6f1f-42ce-819b-514ca9c4216bn%40googlegroups.com.
[go-nuts] Re: http server unable to authorize other CA authorities on windows
Hello, The issue is resolved. Golang automatically search the CA's at appropriate path <https://stackoverflow.com/questions/40051213/where-is-golang-picking-up-root-cas-from> in case of unix flavored machines But, in case of os esp. windows I don't find any possibility or doc for guiding a process to trust mmc based CA's. We just have to merge the certs like this: -BEGIN CERTIFICATE- YOUR CERT YOUR CERT YOUR CERT -END CERTIFICATE- -BEGIN CERTIFICATE- SOME INTERMEDIATE CERT SOME INTERMEDIATE CERT SOME INTERMEDIATE CERT -END CERTIFICATE- -BEGIN CERTIFICATE- ANOTHER INTERMEDIATE CERT ANOTHER INTERMEDIATE CERT ANOTHER INTERMEDIATE CERT ANOTHER INTERMEDIATE CERT -END CERTIFICATE- and use it as single one with this method(there are other ways also available). ListenAndServeTLS() ` For more details check these articles: http.ListenAndServeTLS with multiple certificates <https://stackoverflow.com/questions/32175300/http-listenandservetls-with-multiple-certificates> How to provide CA certs for ListenAndServeTLS function <https://stackoverflow.com/questions/34689277/how-to-provide-ca-certs-for-listenandservetls-function/49354072> On Monday, 28 September 2020 at 19:30:40 UTC+5:30 smartaq...@gmail.com wrote: > Team, > > Hi all, hope you're doing well. > > I have hosted a small api on windows 10 machine which I'm using as a > webhook receiver. The CA authority of webhook sender is different from the > CA authority of the golang api. > > Code of API is:- > > --- > func main() { > caCertPool := x509.NewCertPool() > caCert2, _ := ioutil.ReadFile(" .pem ") > caCertPool.AppendCertsFromPEM(caCert2) > tlsConfig := &tls.Config{ > RootCAs:caCertPool, > InsecureSkipVerify: false,//tried with true and > false both > ClientCAs: caCertPool, //tried by giving and > removing this property as well. > } > tlsConfig.BuildNameToCertificate() > > > srv := &http.Server{Addr: ":443", TLSConfig: tlsConfig, Handler: > http.HandlerFunc(handle)} > log.Fatal(srv.ListenAndServeTLS("certificate.crt", "certificate.key")) > } > > func handle(w http.ResponseWriter, r *http.Request) { > // Log the request protocol > log.Printf("Got connection: %s", r.Proto) > // Send a message back to the client > w.Write([]byte("Hello")) > } > > -- > > *".pem" * :- this has the chain of all CA including > webhook sender > *"certificate.crt "* :- this certificate has complete root chain of other > CA > > Still whenever I'm trying to make a call from webhook sender(github) to my > api a tls handshake error occurs. > > Error at webhook sender side:- *Peer certificate cannot be authenticated > with given CA certificates webhook* > > Error at webhook receiver side:- *TLS handshake error* > > The moment I've used another certificate in the method > *ListenAndServeTLS, *created with the CA authority same as that of > webhook sender, everything worked fine. > > In production, we're not allowed to make any certificate in that CA. Can > anyone suggest me the procedure of trusting other CA's in case of windows > machines with golang. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/d89c1a25-c341-49eb-92fb-551cab8fa3c1n%40googlegroups.com.