@@ -57,17 +57,9 @@ type JsonStreamCallback func(json.RawMessage) error
5757// GLOBALS
5858
5959const (
60- DefaultTimeout = time .Second * 30
61- DefaultUserAgent = "github.com/mutablelogic/go-client"
62- PathSeparator = "/"
63- ContentTypeAny = types .ContentTypeAny
64- ContentTypeJson = types .ContentTypeJSON
65- ContentTypeJsonStream = "application/x-ndjson"
66- ContentTypeTextXml = types .ContentTypeTextXml
67- ContentTypeApplicationXml = types .ContentTypeXML
68- ContentTypeTextPlain = types .ContentTypeTextPlain
69- ContentTypeTextHTML = "text/html"
70- ContentTypeBinary = types .ContentTypeBinary
60+ DefaultTimeout = time .Second * 30
61+ DefaultUserAgent = "github.com/mutablelogic/go-client"
62+ PathSeparator = "/"
7163)
7264
7365///////////////////////////////////////////////////////////////////////////////
@@ -200,19 +192,19 @@ func (client *Client) request(ctx context.Context, method, accept, mimetype stri
200192 // Set the credentials and user agent
201193 if body != nil {
202194 if mimetype == "" {
203- mimetype = ContentTypeJson
195+ mimetype = types . ContentTypeJSON
204196 }
205197 r .Header .Set ("Content-Type" , mimetype )
206198 }
207199 if accept != "" {
208200 r .Header .Set ("Accept" , accept )
209201 } else {
210- r .Header .Set ("Accept" , ContentTypeAny )
202+ r .Header .Set ("Accept" , types . ContentTypeAny )
211203 }
212204 // For SSE or NDJSON streams, disable caching and Nginx proxy buffering so
213205 // events are delivered immediately rather than held in intermediate buffers.
214206 // Accept may be a comma-separated list so use Contains rather than ==.
215- if strings .Contains (accept , ContentTypeTextStream ) || strings .Contains (accept , ContentTypeJsonStream ) || strings . Contains ( accept , types .ContentTypeJSONStream ) {
207+ if strings .Contains (accept , ContentTypeTextStream ) || strings .Contains (accept , types .ContentTypeJSONStream ) {
216208 r .Header .Set ("Cache-Control" , "no-cache" )
217209 r .Header .Set ("X-Accel-Buffering" , "no" )
218210 }
@@ -361,7 +353,7 @@ func do(client *http.Client, req *http.Request, accept string, strict bool, out
361353 // When in strict mode, check content type returned is as expected.
362354 // Use 406 Not Acceptable since this is client-side validation that the
363355 // server's response doesn't match our Accept header expectations.
364- if strict && (accept != "" && accept != ContentTypeAny ) {
356+ if strict && (accept != "" && accept != types . ContentTypeAny ) {
365357 if mimetype != accept {
366358 return httpresponse .Err (http .StatusNotAcceptable ).Withf ("strict mode: expected %q, got %q" , accept , mimetype )
367359 }
@@ -389,7 +381,7 @@ func do(client *http.Client, req *http.Request, accept string, strict bool, out
389381 }
390382
391383 switch {
392- case mimetype == ContentTypeJson || isJSONStreamContentType ( mimetype ) :
384+ case mimetype == types . ContentTypeJSON || mimetype == types . ContentTypeJSONStream :
393385 dec := json .NewDecoder (response .Body )
394386 if reqopts .jsonStreamCallback != nil {
395387 for {
@@ -416,11 +408,11 @@ func do(client *http.Client, req *http.Request, accept string, strict bool, out
416408 return err
417409 }
418410 }
419- case mimetype == ContentTypeTextXml || mimetype == ContentTypeApplicationXml :
411+ case mimetype == types . ContentTypeTextXml || mimetype == types . ContentTypeXML :
420412 if err := xml .NewDecoder (response .Body ).Decode (out ); err != nil {
421413 return err
422414 }
423- case mimetype == ContentTypeTextPlain :
415+ case mimetype == types . ContentTypeTextPlain :
424416 data , err := io .ReadAll (response .Body )
425417 if err != nil {
426418 return err
@@ -455,7 +447,7 @@ func do(client *http.Client, req *http.Request, accept string, strict bool, out
455447func respContentType (resp * http.Response ) (string , error ) {
456448 contenttype := resp .Header .Get ("Content-Type" )
457449 if contenttype == "" {
458- return ContentTypeBinary , nil
450+ return types . ContentTypeBinary , nil
459451 }
460452 if mimetype , err := types .ParseContentType (contenttype ); err != nil {
461453 return contenttype , httpresponse .Err (http .StatusUnsupportedMediaType ).With (contenttype )
0 commit comments