forked from 30x/libgozerian
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.go
More file actions
64 lines (56 loc) · 1.71 KB
/
commands.go
File metadata and controls
64 lines (56 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
//go:generate stringer -type=CommandID
// Mapping of command IDs to names is generated by stringer -- re run
// "go generate" if you change the ID list below.
// CommandID identifies one of the commands that libgozerian sends back via its
// C interface.
type CommandID int
const (
// DONE indicates that no more commands will be delivered for this request or response
DONE CommandID = iota
// ERRR indicates that there was an error processing a request or response. No more
// commands will be delivered.
ERRR
// RBOD indicates that the request or response requests that the message body
// be delivered via one of the C functions for that purpose.
RBOD
// WHDR indicates that the request or response headers must be re-written to
// match the new values.
WHDR
// WURI indicates that the request URI must change
WURI
// WSTA indicates that the HTTP status code on the response must change
WSTA
// SWCH indicates that the request or response path has changed so that
// libgozerian will provide the complete response. If we are on the request path,
// no target server should be invoked. If are are on the response path, then
// the existing response should be discarded.
SWCH
// WBOD indicates that the request or response body is being rewritten and should
// be replaced with the chunks identified by this command.
WBOD
)
const (
cmdDone = "DONE"
cmdErrr = "ERRR"
cmdRbod = "RBOD"
cmdWhdr = "WHDR"
cmdWURI = "WURI"
cmdWsta = "WSTA"
cmdSwch = "SWCH"
cmdWbod = "WBOD"
)
type command struct {
id CommandID
msg string
}
func createErrorCommand(err error) command {
return command{
id: ERRR,
msg: err.Error(),
}
}
func (c command) String() string {
pfx := c.id.String()
return pfx + c.msg
}