FAQ
Is there a way to set a timeout limit for net/http's client.Get()?
Currently I have this much;

func disallowRedirect(req *http.Request, via []*http.Request) error {
return errors.New("Redirection is not allowed.")
}
func somefunction(url string, timeout float64, userAgent string)
client := &http.Client(
         CheckRedirect: disallowRedirect,
     )
     req, err := http.NewRequest("GET", url, nil);
     if err != nil {
         return
     }
     req.Header.add("User-Agent", userAgent);
     client.Do(req)
}

Search Discussions

  • Piyush Madan at Jun 3, 2013 at 12:58 pm

    Yaşar Arabacı if you found the answer to this question please post here,
    I would be really grateful.

    Otherwise, can someone else please help me out here? How do you set the
    timeout of a Get request in 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 [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.
  • Fatih Arslan at Jun 3, 2013 at 1:15 pm
    You can use https://github.com/mreiferson/go-httpclient

    From Readme:

    HttpClient wraps Go's built in HTTP client providing an API to:

    - set timeouts
    - separate connect timeout
    - request based timeout (*not* just read/write deadline)
    - easy access to the connection object for a given request


    --
    Fatih Arslan

    On 3 June 2013 Monday at 13:50, Piyush Madan wrote:

    Yaşar Arabacı if you found the answer to this question please post here, I would be really grateful.


    Otherwise, can someone else please help me out here? How do you set the timeout of a Get request in 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+[email protected] (mailto:[email protected]).
    For more options, visit https://groups.google.com/groups/opt_out.


    --
    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 [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.
  • Brad Fitzpatrick at Jun 3, 2013 at 2:21 pm
    Your "timeout float64" should be a time.Duration, not a float64--- is that
    float64 seconds, days, weeks?

    See http://golang.org/pkg/net/http/#Transport and its ResponseHeaderTimeout.


    On Tue, Jan 22, 2013 at 11:23 AM, Yaşar Arabacı wrote:

    Is there a way to set a timeout limit for net/http's client.Get()?
    Currently I have this much;

    func disallowRedirect(req *http.Request, via []*http.Request) error {
    return errors.New("Redirection is not allowed.")
    }
    func somefunction(url string, timeout float64, userAgent string)
    client := &http.Client(
    CheckRedirect: disallowRedirect,
    )
    req, err := http.NewRequest("GET", url, nil);
    if err != nil {
    return
    }
    req.Header.add("User-Agent", userAgent);
    client.Do(req)
    }

    --
    http://yasararabaci.tumblr.com

    --

    --
    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 [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.
  • John Nagle at Jun 3, 2013 at 5:37 pm

    On 6/3/2013 7:21 AM, Brad Fitzpatrick wrote:
    Your "timeout float64" should be a time.Duration, not a float64--- is that
    float64 seconds, days, weeks?

    See http://golang.org/pkg/net/http/#Transport and its ResponseHeaderTimeout.
         For real-world HTTP use with arbitrary sites, you have to have
    timeouts on everything, not just headers. Some sites quickly respond
    with a header, then stall while providing the response body.
    (Some content management systems do this when overloaded.)

         Also, does ResponseHeaderTimeout handle stalls during SSL
    negotiation? (Try "https://soton.ac.uk/". Your browser will
    be stuck for minutes.)

         John Nagle

    --
    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 [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.
  • Brad Fitzpatrick at Jun 4, 2013 at 5:22 pm
    The other timeouts are under your control.



    On Mon, Jun 3, 2013 at 10:36 AM, John Nagle wrote:
    On 6/3/2013 7:21 AM, Brad Fitzpatrick wrote:
    Your "timeout float64" should be a time.Duration, not a float64--- is that
    float64 seconds, days, weeks?

    See http://golang.org/pkg/net/http/#Transport and its
    ResponseHeaderTimeout.

    For real-world HTTP use with arbitrary sites, you have to have
    timeouts on everything, not just headers. Some sites quickly respond
    with a header, then stall while providing the response body.
    (Some content management systems do this when overloaded.)

    Also, does ResponseHeaderTimeout handle stalls during SSL
    negotiation? (Try "https://soton.ac.uk/". Your browser will
    be stuck for minutes.)

    John Nagle

    --
    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 [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.

    --
    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 [email protected].
    For more options, visit https://groups.google.com/groups/opt_out.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 22, '13 at 7:23p
activeJun 4, '13 at 5:22p
posts6
users5
websitegolang.org

People

Translate

site design / logo © 2023 Grokbase