@@ -1713,6 +1713,17 @@ static private Format getHeaderFormat(BodyPart part) {
17131713 return null ;
17141714 }
17151715
1716+ // Bulk multi-document reads carry the version as a "versionId" param on Content-Disposition, not as an ETag header.
1717+ static private long getHeaderVersion (BodyPart part ) {
1718+ String contentDisposition = getHeader (part , HEADER_CONTENT_DISPOSITION );
1719+ String versionRegex = ".* versionId=([0-9]+).*" ;
1720+ if (contentDisposition != null && contentDisposition .matches (versionRegex )) {
1721+ String version = contentDisposition .replaceFirst ("^.*" + versionRegex + ".*$" , "$1" );
1722+ return Utilities .parseLong (version , DocumentDescriptor .UNKNOWN_VERSION );
1723+ }
1724+ return DocumentDescriptor .UNKNOWN_VERSION ;
1725+ }
1726+
17161727 static private void updateMimetype (ContentDescriptor descriptor ,
17171728 Headers headers ) {
17181729 updateMimetype (descriptor , getHeaderMimetype (headers .get (HEADER_CONTENT_TYPE )));
@@ -1837,10 +1848,6 @@ static private void updateVersion(DocumentDescriptor descriptor, Headers headers
18371848 updateVersion (descriptor , extractVersion (headers .get (HEADER_ETAG )));
18381849 }
18391850
1840- static private void updateVersion (DocumentDescriptor descriptor , String header ) {
1841- updateVersion (descriptor , extractVersion (header ));
1842- }
1843-
18441851 static private void updateVersion (DocumentDescriptor descriptor , long version ) {
18451852 descriptor .setVersion (version );
18461853 }
@@ -4436,6 +4443,7 @@ static class OkHttpResult {
44364443 private Format format ;
44374444 private String mimetype ;
44384445 private long length ;
4446+ private long version = DocumentDescriptor .UNKNOWN_VERSION ;
44394447
44404448 OkHttpResult (RequestLogger reqlog , BodyPart part ) {
44414449 this .reqlog = reqlog ;
@@ -4490,6 +4498,11 @@ public long getLength() {
44904498 return length ;
44914499 }
44924500
4501+ public long getVersion () {
4502+ extractHeaders ();
4503+ return version ;
4504+ }
4505+
44934506 public String getHeader (String name ) {
44944507 extractHeaders ();
44954508 List <String > values = headers .get (name );
@@ -4515,6 +4528,7 @@ private void extractHeaders() {
45154528 mimetype = getHeaderMimetype (OkHttpServices .getHeader (part , HEADER_CONTENT_TYPE ));
45164529 length = getHeaderLength (OkHttpServices .getHeader (part , HEADER_CONTENT_LENGTH ));
45174530 uri = getHeaderUri (part );
4531+ version = getHeaderVersion (part );
45184532 extractedHeaders = true ;
45194533 } catch (MessagingException e ) {
45204534 throw new MarkLogicIOException (e );
@@ -4688,7 +4702,7 @@ public DocumentDescriptor getDescriptor() {
46884702 updateFormat (descriptor , getFormat ());
46894703 updateMimetype (descriptor , getMimetype ());
46904704 updateLength (descriptor , getLength ());
4691- updateVersion (descriptor , content .getHeader ( HEADER_ETAG ));
4705+ updateVersion (descriptor , content .getVersion ( ));
46924706 return descriptor ;
46934707 }
46944708
0 commit comments