Skip to content

Support for custom headers in mutipart form-data #180

@pmstss

Description

@pmstss

Description

According to OpenAPI 3.x specification, it's possible to specify custom headers for parts of multipart requests via EncodingObject.headers

Steps to reproduce

Pass the my-schema.yaml (see below) to the oas2har as follows:

import { oas2har } from '@har-sdk/oas';
import { readFile } from 'fs';
import { promisify } from 'util';
import { load } from 'js-yaml';

const content = await promisify(readFile)(
  './my-schema.yaml',
  'utf8'
);

const result = oas2har(load(content) as OpenAPIV3.Document);
my-schema.yaml
openapi: 3.0.1
info:
  title: Custom headers in multipart form-data
  version: 1.0.0
servers:
  - url: https://brightsec.com
paths:
  /upload:
    post:
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                image: {}
            encoding:
              image:
                contentType: image/png, image/jpeg
                headers:
                 X-Custom-Header:
                    schema:
                      type: string
        required: true
      responses:
        201:
          description: Successful upload
          content: {}

Actual result

Multipart form data in HAR entry postData doesn't include X-Custom-Header:

    "postData": {
      "mimeType": "multipart/form-data; boundary=956888039105887155673143",
      "text": "--956888039105887155673143\r\nContent-Disposition: form-data; name=\"image\"; filename=\"image\"\r\nContent-Type: application/octet-stream\r\nContent-Transfer-Encoding: base64\r\n\r\niVBORw0KGgo=\r\n--9568880391058
87155673143--"
    }

Expected result

X-Custom-Header presents in postData

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions