forked from moby/moby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add long-running client session endpoint
Signed-off-by: Tonis Tiigi <[email protected]>
- Loading branch information
1 parent
f88626b
commit ec7b623
Showing
17 changed files
with
660 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package session | ||
|
||
import ( | ||
"net/http" | ||
|
||
"golang.org/x/net/context" | ||
) | ||
|
||
// Backend abstracts an session receiver from an http request. | ||
type Backend interface { | ||
HandleHTTPRequest(ctx context.Context, w http.ResponseWriter, r *http.Request) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package session | ||
|
||
import "github.com/docker/docker/api/server/router" | ||
|
||
// sessionRouter is a router to talk with the session controller | ||
type sessionRouter struct { | ||
backend Backend | ||
routes []router.Route | ||
} | ||
|
||
// NewRouter initializes a new session router | ||
func NewRouter(b Backend) router.Router { | ||
r := &sessionRouter{ | ||
backend: b, | ||
} | ||
r.initRoutes() | ||
return r | ||
} | ||
|
||
// Routes returns the available routers to the session controller | ||
func (r *sessionRouter) Routes() []router.Route { | ||
return r.routes | ||
} | ||
|
||
func (r *sessionRouter) initRoutes() { | ||
r.routes = []router.Route{ | ||
router.Experimental(router.NewPostRoute("/session", r.startSession)), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package session | ||
|
||
import ( | ||
"net/http" | ||
|
||
apierrors "github.com/docker/docker/api/errors" | ||
"golang.org/x/net/context" | ||
) | ||
|
||
func (sr *sessionRouter) startSession(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { | ||
err := sr.backend.HandleHTTPRequest(ctx, w, r) | ||
if err != nil { | ||
return apierrors.NewBadRequestError(err) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package client | ||
|
||
import ( | ||
"net" | ||
"net/http" | ||
|
||
"golang.org/x/net/context" | ||
) | ||
|
||
// DialSession returns a connection that can be used communication with daemon | ||
func (cli *Client) DialSession(ctx context.Context, proto string, meta map[string][]string) (net.Conn, error) { | ||
req, err := http.NewRequest("POST", "/session", nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
req = cli.addHeaders(req, meta) | ||
|
||
return cli.setupHijackConn(req, proto) | ||
} |
Oops, something went wrong.