<commit_before>// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.

couchTests.attachments_multipart= function(debug) {
  var db = new CouchDB("test_suite_db", {"X-Couch-Full-Commit":"false"});
  db.deleteDb();
  db.createDb();
  if (debug) debugger;
  
  // mime multipart
            
  xhr = CouchDB.request("PUT", "/test_suite_db/multipart", {
    headers: {"Content-Type": "multipart/related;boundary=\"abc123\""},
    body:
      "--abc123\r\n" +
      "content-type: application/json\r\n" +
      "\r\n" +
      JSON.stringify({
        "body":"This is a body.",
        "_attachments":{
          "foo.txt": {
            "follows":true,
            "content_type":"application/test",
            "length":21
            },
          "bar.txt": {
            "follows":true,
            "content_type":"application/test",
            "length":20
            },
          "baz.txt": {
            "follows":true,
            "content_type":"application/test",
            "length":19
            }
          }
        }) +
      "\r\n--abc123\r\n" +
      "\r\n" +
      "this is 21 chars long" +
      "\r\n--abc123\r\n" +
      "\r\n" +
      "this is 20 chars lon" +
      "\r\n--abc123\r\n" +
      "\r\n" +
      "this is 19 chars lo" +
      "\r\n--abc123--"
    });
    
  var result = JSON.parse(xhr.responseText);
  
  T(result.ok);
  
  
    
  TEquals(201, xhr.status, "should send 201 Accepted");
  
  xhr = CouchDB.request("GET", "/test_suite_db/multipart/foo.txt");
  
  T(xhr.responseText == "this is 21 chars long");
  
  xhr = CouchDB.request("GET", "/test_suite_db/multipart/bar.txt");
  
  T(xhr.responseText == "this is 20 chars lon");
  
  xhr = CouchDB.request("GET", "/test_suite_db/multipart/baz.txt");
  
  T(xhr.responseText == "this is 19 chars lo");
  
  // now edit an attachment
  
  var doc = db.open("multipart");
  var firstrev = doc._rev;
  
  T(doc._attachments["foo.txt"].stub == true);
  T(doc._attachments["bar.txt"].stub == true);
  T(doc._attachments["baz.txt"].stub == true);
  
  //lets change attachment bar
  delete doc._attachments["bar.txt"].stub; // remove stub member (or could set to false)
  doc._attachments["bar.txt"].length = 18;
  doc._attachments["bar.txt"].follows = true;
  //lets delete attachment baz:
  delete doc._attachments["baz.txt"];
  
  var xhr = CouchDB.request("PUT", "/test_suite_db/multipart", {
    headers: {"Content-Type": "multipart/related;boundary=\"abc123\""},
    body:
      "--abc123\r\n" +
      "content-type: application/json\r\n" +
      "\r\n" +
      JSON.stringify(doc) +
      "\r\n--abc123\r\n" +
      "\r\n" +
      "this is 18 chars l" +
      "\r\n--abc123--"
    });
  
  xhr = CouchDB.request("GET", "/test_suite_db/multipart/bar.txt");
  
  T(xhr.responseText == "this is 18 chars l");
  <commit_msg>Add missing option to multipart/related GETs<commit_after>// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.

couchTests.attachments_multipart= function(debug) {
  var db = new CouchDB("test_suite_db", {"X-Couch-Full-Commit":"false"});
  db.deleteDb();
  db.createDb();
  if (debug) debugger;
  
  // mime multipart
            
  xhr = CouchDB.request("PUT", "/test_suite_db/multipart", {
    headers: {"Content-Type": "multipart/related;boundary=\"abc123\""},
    body:
      "--abc123\r\n" +
      "content-type: application/json\r\n" +
      "\r\n" +
      JSON.stringify({
        "body":"This is a body.",
        "_attachments":{
          "foo.txt": {
            "follows":true,
            "content_type":"application/test",
            "length":21
            },
          "bar.txt": {
            "follows":true,
            "content_type":"application/test",
            "length":20
            },
          "baz.txt": {
            "follows":true,
            "content_type":"text/plain",
            "length":19
            }
          }
        }) +
      "\r\n--abc123\r\n" +
      "\r\n" +
      "this is 21 chars long" +
      "\r\n--abc123\r\n" +
      "\r\n" +
      "this is 20 chars lon" +
      "\r\n--abc123\r\n" +
      "\r\n" +
      "this is 19 chars lo" +
      "\r\n--abc123--"
    });
    
  var result = JSON.parse(xhr.responseText);
  
  T(result.ok);
  
  
    
  TEquals(201, xhr.status, "should send 201 Accepted");
  
  xhr = CouchDB.request("GET", "/test_suite_db/multipart/foo.txt");
  
  T(xhr.responseText == "this is 21 chars long");
  
  xhr = CouchDB.request("GET", "/test_suite_db/multipart/bar.txt");
  
  T(xhr.responseText == "this is 20 chars lon");
  
  xhr = CouchDB.request("GET", "/test_suite_db/multipart/baz.txt");
  
  T(xhr.responseText == "this is 19 chars lo");
  
  // now edit an attachment
  
  var doc = db.open("multipart", {att_encoding_info: true});
  var firstrev = doc._rev;
  
  T(doc._attachments["foo.txt"].stub == true);
  T(doc._attachments["bar.txt"].stub == true);
  T(doc._attachments["baz.txt"].stub == true);
  TEquals("undefined", typeof doc._attachments["foo.txt"].encoding);
  TEquals("undefined", typeof doc._attachments["bar.txt"].encoding);
  TEquals("gzip", doc._attachments["baz.txt"].encoding);
  
  //lets change attachment bar
  delete doc._attachments["bar.txt"].stub; // remove stub member (or could set to false)
  doc._attachments["bar.txt"].length = 18;
  doc._attachments["bar.txt"].follows = true;
  //lets delete attachment baz:
  delete doc._attachments["baz.txt"];
  
  var xhr = CouchDB.request("PUT", "/test_suite_db/multipart", {
    headers: {"Content-Type": "multipart/related;boundary=\"abc123\""},
    body:
      "--abc123\r\n" +
      "content-type: application/json\r\n" +
      "\r\n" +
      JSON.stringify(doc) +
      "\r\n--abc123\r\n" +
      "\r\n" +
      "this is 18 chars l" +
      "\r\n--abc123--"
    });
  
  xhr = CouchDB.request("GET", "/test_suite_db/multipart/bar.txt");
  
  T(xhr.responseText == "this is 18 chars l");
  
{'fraction_non_alphanumeric': 0.1680035000729182, 'fraction_numerical': 0.018667055563657577, 'mean_word_length': 2.3551859099804306, 'pattern_counts': {'":': 34, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3087993', 'n_tokens_mistral': 2427, 'n_tokens_neox': 2306, 'n_words': 517}