• Joe Tsai's avatar
    net/http/httptest: allow creation of Server manually · 14b07dfc
    Joe Tsai authored
    The Server struct has exported fields, which allows users to manually
    create a Server object without using using NewServer or NewTLSServer
    and directly call Start or StartTLS on their object.
    
    In order to ensure that manual creation of Server works, the
    NewUnstartedServer function should not initialize Server in any way
    that the user was not able to do themselves. For example, the setting
    of a unexported filed, client, is not something a user can do.
    Thus, rather than setting the client field in NewUnstartedServer,
    we lazily initialize it when Start or StartTLS is called.
    
    Otherwise, the Server logic can nil panic later when it assumes that this
    field has been initialized.
    
    Fixes #20871
    
    Change-Id: I65c6a9f893ea963b0fbad0990b33af08007c1140
    Reviewed-on: https://go-review.googlesource.com/47353Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
    14b07dfc
Name
Last commit
Last update
..
example_test.go Loading commit data...
httptest.go Loading commit data...
httptest_test.go Loading commit data...
recorder.go Loading commit data...
recorder_test.go Loading commit data...
server.go Loading commit data...
server_test.go Loading commit data...