@@ -84,7 +84,7 @@ func (xTransport *XTransport) rebuildTransport() {
8484 xTransport .transport = transport
8585}
8686
87- func (xTransport * XTransport ) Fetch (method string , url * url.URL , accept string , contentType string , body * io.ReadCloser , timeout time.Duration ) (* http.Response , time.Duration , error ) {
87+ func (xTransport * XTransport ) Fetch (method string , url * url.URL , accept string , contentType string , body * io.ReadCloser , timeout time.Duration , padding * string ) (* http.Response , time.Duration , error ) {
8888 if timeout <= 0 {
8989 timeout = xTransport .timeout
9090 }
@@ -96,6 +96,9 @@ func (xTransport *XTransport) Fetch(method string, url *url.URL, accept string,
9696 if len (contentType ) > 0 {
9797 header ["Content-Type" ] = []string {contentType }
9898 }
99+ if padding != nil {
100+ header ["X-Pad" ] = []string {* padding }
101+ }
99102 req := & http.Request {
100103 Method : method ,
101104 URL : url ,
@@ -184,24 +187,36 @@ func (xTransport *XTransport) Fetch(method string, url *url.URL, accept string,
184187}
185188
186189func (xTransport * XTransport ) Get (url * url.URL , accept string , timeout time.Duration ) (* http.Response , time.Duration , error ) {
187- return xTransport .Fetch ("GET" , url , "" , "" , nil , timeout )
190+ return xTransport .Fetch ("GET" , url , "" , "" , nil , timeout , nil )
188191}
189192
190- func (xTransport * XTransport ) Post (url * url.URL , accept string , contentType string , body []byte , timeout time.Duration ) (* http.Response , time.Duration , error ) {
193+ func (xTransport * XTransport ) Post (url * url.URL , accept string , contentType string , body []byte , timeout time.Duration , padding * string ) (* http.Response , time.Duration , error ) {
191194 bc := ioutil .NopCloser (bytes .NewReader (body ))
192- return xTransport .Fetch ("POST" , url , accept , contentType , & bc , timeout )
195+ return xTransport .Fetch ("POST" , url , accept , contentType , & bc , timeout , padding )
193196}
197+
194198func (xTransport * XTransport ) DoHQuery (useGet bool , url * url.URL , body []byte , timeout time.Duration ) (* http.Response , time.Duration , error ) {
199+ padLen := 63 - (len (body )+ 63 )& 63
200+ padding := xTransport .makePad (padLen )
195201 dataType := "application/dns-udpwireformat"
196202 if useGet {
197203 qs := url .Query ()
198204 qs .Add ("ct" , "" )
199205 encBody := base64 .RawURLEncoding .EncodeToString (body )
200206 qs .Add ("body" , encBody )
201207 qs .Add ("dns" , encBody )
208+ qs .Add ("random_padding" , * padding )
202209 url2 := * url
203210 url2 .RawQuery = qs .Encode ()
204211 return xTransport .Get (& url2 , dataType , timeout )
205212 }
206- return xTransport .Post (url , dataType , dataType , body , timeout )
213+ return xTransport .Post (url , dataType , dataType , body , timeout , padding )
214+ }
215+
216+ func (xTransport * XTransport ) makePad (padLen int ) * string {
217+ if padLen <= 0 {
218+ return nil
219+ }
220+ padding := strings .Repeat ("X" , padLen )
221+ return & padding
207222}
0 commit comments