Skip to content
This repository was archived by the owner on Jul 30, 2023. It is now read-only.

Commit 1623f9b

Browse files
committed
chore(Readme - add setupRedirects method), chore(Android - allow string in body)
1 parent 6ef62f4 commit 1623f9b

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ Option | Description
132132
`allowInvalidCertificates?: boolean` | Default: `false`. This should **always** be `false` if you are using SSL pinning. Set this to `true` if you're using a self-signed certificate.
133133
`validatesDomainName?: boolean` | Default: `true`. Determines if the domain name should be validated with your pinned certificate.
134134

135+
#### Setup redirects
136+
```typescript
137+
import * as Https from 'nativescript-https'
138+
Https.setupRedirects(false)
139+
```
140+
All requests after calling this method will no longer make redirects until it is re-enabled once again.
141+
135142
## `iOS` Troubleshooting
136143
> ### Please educate yourself on iOS's [App Transport Security](https://github.com/codepath/ios_guides/wiki/App-Transport-Security) before starting beef!
137144

https.android.js

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

https.android.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as application from 'tns-core-modules/application'
22
import { HttpRequestOptions, Headers, HttpResponse } from 'tns-core-modules/http'
3-
import { isDefined, isNullOrUndefined } from 'tns-core-modules/utils/types'
3+
import { isDefined, isNullOrUndefined, isObject } from 'tns-core-modules/utils/types'
44
import * as Https from './https.common'
55

66
interface Ipeer {
@@ -176,9 +176,13 @@ export function request(opts: Https.HttpsRequestOptions): Promise<Https.HttpsRes
176176
} else {
177177
let type = <string>opts.headers['Content-Type'] || 'application/json'
178178
let body = <any>opts.body || {}
179+
179180
try {
180-
body = JSON.stringify(body)
181+
if (isObject(body)) {
182+
body = JSON.stringify(body)
183+
}
181184
} catch (e) { }
185+
182186
request[methods[opts.method]](okhttp3.RequestBody.create(
183187
okhttp3.MediaType.parse(type),
184188
body

https.common.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface HttpsRequestOptions {
1616
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD'
1717
headers?: Headers
1818
params?: HttpsRequestObject
19-
body?: HttpsRequestObject
19+
body?: HttpsRequestObject | string
2020
}
2121

2222
export interface HttpsResponse {

https.ios.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as application from 'tns-core-modules/application'
22
import { HttpRequestOptions, Headers, HttpResponse } from 'tns-core-modules/http'
3-
import { isDefined, isNullOrUndefined, isObject } from 'tns-core-modules/utils/types'
3+
import { isDefined, isNullOrUndefined, isObject, isString } from 'tns-core-modules/utils/types'
44
import * as Https from './https.common'
55

66
interface Ipolicies {

0 commit comments

Comments
 (0)