@@ -16,6 +16,42 @@ import (
16
16
"golang.org/x/xerrors"
17
17
)
18
18
19
+ const (
20
+ // "Header Content-Length" is the HTTP header name of the length of the content part in bytes. This header is required.
21
+ // This entity header indicates the size of the entity-body, in bytes, sent to the recipient.
22
+ //
23
+ // RFC 7230, section 3.3.2: Content-Length:
24
+ // https://tools.ietf.org/html/rfc7230#section-3.3.2
25
+ HeaderContentLength = "Content-Length"
26
+
27
+ // "HeaderContentType" is the mime type of the content part. Defaults to "application/vscode-jsonrpc; charset=utf-8".
28
+ // This entity header is used to indicate the media type of the resource.
29
+ //
30
+ // RFC 7231, section 3.1.1.5: Content-Type:
31
+ // https://tools.ietf.org/html/rfc7231#section-3.1.1.5
32
+ HeaderContentType = "Content-Type"
33
+
34
+ // HeaderContentSeparator is the header and content part separator.
35
+ HeaderContentSeparator = "\r \n "
36
+
37
+ headerSeparatorComma = ":"
38
+ )
39
+
40
+ const (
41
+ // ContentTypeJSONRPC is the custom mime type content for the Language Server Protocol.
42
+ ContentTypeJSONRPC = "application/jsonrpc; charset=utf-8"
43
+
44
+ // ContentTypeVSCodeJSONRPC is the default mime type content for the Language Server Protocol Specification.
45
+ ContentTypeVSCodeJSONRPC = "application/vscode-jsonrpc; charset=utf-8"
46
+ )
47
+
48
+ const (
49
+ // HeaderContentLengthFmt is the a format of "Content-Length" header for fmt function arg.
50
+ HeaderContentLengthFmt = HeaderContentLength + headerSeparatorComma + " %d" + HeaderContentSeparator
51
+ // HeaderContentTypeFmt is the a format of "Content-Type" header for fmt function arg.
52
+ HeaderContentTypeFmt = HeaderContentType + headerSeparatorComma + " %s" + HeaderContentSeparator
53
+ )
54
+
19
55
// Stream abstracts the transport mechanics from the JSON RPC protocol.
20
56
type Stream interface {
21
57
// Read gets the next message from the stream.
@@ -97,7 +133,7 @@ func (s *stream) Write(ctx context.Context, p []byte) (n int, err error) {
97
133
}
98
134
99
135
s .Lock ()
100
- n , err = fmt .Fprintf (s .out , "Content-Length: %v \r \n \r \n " , len (p ))
136
+ n , err = fmt .Fprintf (s .out , HeaderContentLengthFmt + HeaderContentTypeFmt + HeaderContentSeparator , len (p ), ContentTypeJSONRPC )
101
137
if err == nil {
102
138
n , err = s .out .Write (p )
103
139
}
0 commit comments