Merge branch 'main' into add-feature-checkbox

This commit is contained in:
Ashita Prasad
2024-01-06 03:04:06 +05:30
committed by GitHub
5 changed files with 17 additions and 5 deletions

View File

@ -55,8 +55,11 @@ class DartHttpCodeGen {
final strContent = CodeExpression(Code('r\'\'\'$body\'\'\'')); final strContent = CodeExpression(Code('r\'\'\'$body\'\'\''));
dataExp = declareVar('body', type: refer('String')).assign(strContent); dataExp = declareVar('body', type: refer('String')).assign(strContent);
composeHeaders.putIfAbsent(HttpHeaders.contentTypeHeader, final hasContentTypeHeader = composeHeaders.keys.any((k) => k.toLowerCase() == HttpHeaders.contentTypeHeader);
if (!hasContentTypeHeader) {
composeHeaders.putIfAbsent(HttpHeaders.contentTypeHeader,
() => kContentTypeMap[contentType] ?? ''); () => kContentTypeMap[contentType] ?? '');
}
} }
Expression? queryParamExp; Expression? queryParamExp;

View File

@ -105,7 +105,9 @@ print(data.decode("utf-8"))
var headers = requestModel.enabledHeadersMap; var headers = requestModel.enabledHeadersMap;
if (headers.isNotEmpty || hasBody) { if (headers.isNotEmpty || hasBody) {
hasHeaders = true; hasHeaders = true;
if (hasBody) { bool hasContentTypeHeader = headers.keys.any((k) => k.toLowerCase() == HttpHeaders.contentTypeHeader);
if (hasBody && !hasContentTypeHeader) {
headers[HttpHeaders.contentTypeHeader] = headers[HttpHeaders.contentTypeHeader] =
kContentTypeMap[requestModel.requestBodyContentType] ?? ""; kContentTypeMap[requestModel.requestBodyContentType] ?? "";
} }

View File

@ -28,8 +28,11 @@ Future<(http.Response?, Duration?, String?)> request(
if (contentLength > 0) { if (contentLength > 0) {
body = requestBody; body = requestBody;
headers[HttpHeaders.contentLengthHeader] = contentLength.toString(); headers[HttpHeaders.contentLengthHeader] = contentLength.toString();
headers[HttpHeaders.contentTypeHeader] = final hasContentTypeHeader = headers.keys.any((k) => k.toLowerCase() == HttpHeaders.contentTypeHeader);
if (!hasContentTypeHeader) {
headers[HttpHeaders.contentTypeHeader] =
kContentTypeMap[requestModel.requestBodyContentType] ?? ""; kContentTypeMap[requestModel.requestBodyContentType] ?? "";
}
} }
} }
Stopwatch stopwatch = Stopwatch()..start(); Stopwatch stopwatch = Stopwatch()..start();

View File

@ -1,4 +1,5 @@
import 'dart:convert'; import 'dart:convert';
import 'dart:io';
import 'package:apidash/consts.dart'; import 'package:apidash/consts.dart';
import 'package:apidash/utils/utils.dart' show getValidRequestUri; import 'package:apidash/utils/utils.dart' show getValidRequestUri;
import 'package:apidash/models/models.dart' show RequestModel; import 'package:apidash/models/models.dart' show RequestModel;
@ -133,7 +134,9 @@ Map<String, dynamic> requestModelToHARJsonRequest(
var headers = var headers =
useEnabled ? requestModel.enabledHeadersMap : requestModel.headersMap; useEnabled ? requestModel.enabledHeadersMap : requestModel.headersMap;
if (headers.isNotEmpty || hasBody) { if (headers.isNotEmpty || hasBody) {
if (hasBody) { bool hasContentTypeHeader = headers.keys.any((k) => k.toLowerCase() == HttpHeaders.contentTypeHeader);
if (hasBody && !hasContentTypeHeader) {
var m = { var m = {
"name": "Content-Type", "name": "Content-Type",
"value": kContentTypeMap[requestModel.requestBodyContentType] ?? "" "value": kContentTypeMap[requestModel.requestBodyContentType] ?? ""

View File

@ -15,7 +15,8 @@ Map<String, String> headers = {
"Indicates the encoding transformations that have been applied to the entity body of the response.", "Indicates the encoding transformations that have been applied to the entity body of the response.",
"Content-Security-Policy": "Content-Security-Policy":
"Controls the sources from which content can be loaded on a web page to mitigate various types of attacks.", "Controls the sources from which content can be loaded on a web page to mitigate various types of attacks.",
"Content-Type": "Indicates the media type of the entity body.", "Content-Type":
"Indicates the original media type of the resource (prior to any content encoding applied for sending)",
"Cookie": "Used to send previously stored cookies back to the server.", "Cookie": "Used to send previously stored cookies back to the server.",
"Cross-Origin-Embedder-Policy": "Cross-Origin-Embedder-Policy":
"Controls whether a document is allowed to be embedded in another document.", "Controls whether a document is allowed to be embedded in another document.",