FAQ
i want to know why we have to close response body .and another question
what will happen if we read the response body .and the response body is nill

--
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

  • Dave Cheney at Oct 18, 2015 at 3:12 am
    The response body is an io reader streamed from the server, you have to close it to indicate to the server you have finished with the connection. You also have to close it to incidate to the http client that the connection is available for possible reuse.

    Regarding your second question. Can you show a short code sample that illustrates the response body being nil?

    --
    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.
  • Dave Cheney at Oct 18, 2015 at 3:12 am
    The response body is an io reader streamed from the server, you have to close it to indicate to the server you have finished with the connection. You also have to close it to incidate to the http client that the connection is available for possible reuse.

    Regarding your second question. Can you show a short code sample that illustrates the response body being nil?

    --
    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.
  • WALID BELRHALMIA at Oct 18, 2015 at 3:48 am
    i didnt understand the last part :

    You also have to close it to incidate to the http client that the
    connection is available for possible reuse

    could you plz explain

    --
    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.
  • Dave Cheney at Oct 18, 2015 at 3:53 am
    The http package reuses connection across requests (Google http/1.1 connection reuse, sometimes called keep alive)

    To signal to the http package that you are done with a connection and it is safe to reuse that connection you must do so by closing the response body.

    --
    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.
  • Shawn Milochik at Oct 18, 2015 at 3:53 am

    On Sat, Oct 17, 2015 at 11:48 PM, WALID BELRHALMIA wrote:

    i didnt understand the last part :

    You also have to close it to incidate to the http client that the
    connection is available for possible reuse

    could you plz explain
    Your client is your app. Let's pretend it's a Web browser. It connects to
    example.com, perhaps making six connections. It uses those six connections
    because it's faster (until HTTP/2 rolls out), to download all the images,
    CSS, JavaScript, HTML, etc.

    If one of those six connections finishes downloading, say, a .jpg file,
    your browser would like to use it to download something else -- maybe a
    JavaScript file. But it can't until it knows that connection is done with
    its current task.

    --
    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.
  • WALID BELRHALMIA at Oct 18, 2015 at 4:53 am
    what is the difference between doing resp.close() and resp.body.close()

    --
    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.
  • Matt Harden at Oct 18, 2015 at 5:28 am
    resp.Close is a field in the Response struct, not a method. resp.Body.Close
    closes the response body. resp.Close() would not compile.
    On Sat, Oct 17, 2015 at 9:54 PM WALID BELRHALMIA wrote:

    what is the difference between doing resp.close() and resp.body.close()

    --
    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.
  • Dave Cheney at Oct 18, 2015 at 6:37 am
    // Close records whether the header directed that the connection be
             // closed after reading Body. The value is advice for clients: neither
             // ReadResponse nor Response.Write ever closes a connection.
             Close bool <https://golang.org/pkg/builtin/#bool>


    This field records the value of the "Connection"
    header, https://tools.ietf.org/html/rfc2616#section-14.10
    On Sunday, 18 October 2015 15:53:45 UTC+11, WALID BELRHALMIA wrote:

    what is the difference between doing resp.close() and resp.body.close()
    --
    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
postedOct 18, '15 at 2:16a
activeOct 18, '15 at 6:37a
posts9
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase