FAQ
I am performing an HTTP POST to a service that expects I block until it
completes the request. In the background I'll be querying another URL to do
some basic health checking. If the health check indicates something is
going down hill, I'd like to abort the POST, any suggestions?

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Péter Szilágyi at Dec 16, 2014 at 12:54 pm
    Hi,

       I haven't done anything similar, but with a few previous experiences
    related to HTTP API auths, I think a possible location to start your search
    would be the RoundTripper <http://golang.org/pkg/net/http/#RoundTripper>
    interface and the Transport <http://golang.org/pkg/net/http/#Transport>
    struct. Basically, if my hunch is correct, you'll need to create a custom
    transport that implements the RoundTripper, but also has some way of
    dumping pending requests.

    As far as I know, there isn't any simple(r) way to abort a request.

    Cheers,
       Peter
    On Tue, Dec 16, 2014 at 2:25 PM, Craig Wickesser wrote:

    I am performing an HTTP POST to a service that expects I block until it
    completes the request. In the background I'll be querying another URL to do
    some basic health checking. If the health check indicates something is
    going down hill, I'd like to abort the POST, any suggestions?

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • James Bardin at Dec 16, 2014 at 1:16 pm
    You can use Transport.CancelRequest

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Péter Szilágyi at Dec 16, 2014 at 1:33 pm
    Cool :) Live and learn :)
    On Tue, Dec 16, 2014 at 3:16 PM, James Bardin wrote:

    You can use Transport.CancelRequest

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Craig Wickesser at Dec 16, 2014 at 1:53 pm
    Excellent, thanks!
    On Tuesday, December 16, 2014 8:34:12 AM UTC-5, Péter Szilágyi wrote:

    Cool :) Live and learn :)

    On Tue, Dec 16, 2014 at 3:16 PM, James Bardin <j.ba...@gmail.com
    <javascript:>> wrote:
    You can use Transport.CancelRequest

    --
    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 <javascript:>.
    For more options, visit https://groups.google.com/d/optout.
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Craig Wickesser at Dec 16, 2014 at 4:15 pm
    How can I create a client with a transport that I can then call
    CancelRequest on?

    // create a client
    client := http.Client{Timeout: 0}

    // cancel a request --- this does not work because Transport is of type
    RoundTripper
    client.Transport.CancelRequest(req)
    On Tuesday, December 16, 2014 8:53:17 AM UTC-5, Craig Wickesser wrote:

    Excellent, thanks!
    On Tuesday, December 16, 2014 8:34:12 AM UTC-5, Péter Szilágyi wrote:

    Cool :) Live and learn :)
    On Tue, Dec 16, 2014 at 3:16 PM, James Bardin wrote:

    You can use Transport.CancelRequest

    --
    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.
    For more options, visit https://groups.google.com/d/optout.
    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • James Bardin at Dec 16, 2014 at 4:20 pm

    On Tue, Dec 16, 2014 at 11:15 AM, Craig Wickesser wrote:
    How can I create a client with a transport that I can then call
    CancelRequest on?

    // create a client
    client := http.Client{Timeout: 0}
    Assign the Client.Transport to a custom transport. Look at
    DefaultTransport to see how it's configured to start.

    client := &http.Client{
         Transport: myTransport,
    }


    // cancel a request --- this does not work because Transport is of type
    RoundTripper
    client.Transport.CancelRequest(req)
    You can keep a reference to your custom transport, or you can use a type
    assertion:

    client.Transport.(*http.Transport).CancelRequest(req)

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Craig Wickesser at Dec 16, 2014 at 4:28 pm
    Ok, I was looking at the just a moment ago, wasn't sure if that was the
    correct path.

    Have you looked at "context", I wonder if that might be applicable:
    https://blog.golang.org/context

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • James Bardin at Dec 16, 2014 at 4:36 pm

    On Tue, Dec 16, 2014 at 11:28 AM, Craig Wickesser wrote:
    Have you looked at "context", I wonder if that might be applicable:
    https://blog.golang.org/context
    You could use that if you need to provide a context to each request (like
    in the "google" example https://blog.golang.org/context/google/google.go),
    but the request cancelation is still the same.

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 16, '14 at 12:25p
activeDec 16, '14 at 4:36p
posts9
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase