Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: [UI] Upgrade insecure requests #722

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions xinference/web/ui/src/components/fetcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Some users use https proxies for backend service such as nginx.
// So if the url has a https prefix, add a special header to avoid `Mixed Content` issue.
function updateOptions(url, options) {
const update = { ...options }
if (url.startsWith('https://')) {
update.headers = {
...update.headers,
'Content-Security-Policy': 'upgrade-insecure-requests',
}
}
return update
}

export default function fetcher(url, options) {
return fetch(url, updateOptions(url, options))
}
3 changes: 2 additions & 1 deletion xinference/web/ui/src/scenes/launch_model/embeddingCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, { useContext, useEffect, useState } from 'react'
import { v1 as uuidv1 } from 'uuid'

import { ApiContext } from '../../components/apiContext'
import fetcher from '../../components/fetcher'

const CARD_HEIGHT = 270
const CARD_WIDTH = 270
Expand Down Expand Up @@ -33,7 +34,7 @@ const EmbeddingCard = ({ url, modelData }) => {
}

// First fetch request to initiate the model
fetch(url + '/v1/models', {
fetcher(url + '/v1/models', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
5 changes: 3 additions & 2 deletions xinference/web/ui/src/scenes/launch_model/launchEmbedding.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Box, FormControl, TextField } from '@mui/material'
import React, { useContext, useEffect, useState } from 'react'

import { ApiContext } from '../../components/apiContext'
import fetcher from '../../components/fetcher'
import EmbeddingCard from './embeddingCard'

const LaunchEmbedding = () => {
Expand Down Expand Up @@ -34,7 +35,7 @@ const LaunchEmbedding = () => {
try {
setIsCallingApi(true)

const response = await fetch(
const response = await fetcher(
`${endPoint}/v1/model_registrations/embedding`,
{
method: 'GET',
Expand All @@ -44,7 +45,7 @@ const LaunchEmbedding = () => {
const registrations = await response.json()
const newRegistrationData = await Promise.all(
registrations.map(async (registration) => {
const desc = await fetch(
const desc = await fetcher(
`${endPoint}/v1/model_registrations/embedding/${registration.model_name}`,
{
method: 'GET',
Expand Down
3 changes: 2 additions & 1 deletion xinference/web/ui/src/scenes/launch_model/launchLLM.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import React, { useContext, useEffect, useState } from 'react'

import { ApiContext } from '../../components/apiContext'
import fetcher from '../../components/fetcher'
import ModelCard from './modelCard'

const LaunchLLM = () => {
Expand Down Expand Up @@ -59,7 +60,7 @@ const LaunchLLM = () => {
try {
setIsCallingApi(true)

const response = await fetch(
const response = await fetcher(
`${endPoint}/v1/model_registrations/LLM?detailed=true`,
{
method: 'GET',
Expand Down
5 changes: 3 additions & 2 deletions xinference/web/ui/src/scenes/launch_model/launchRerank.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Box, FormControl, TextField } from '@mui/material'
import React, { useContext, useEffect, useState } from 'react'

import { ApiContext } from '../../components/apiContext'
import fetcher from '../../components/fetcher'
import RerankCard from './rerankCard'

const LaunchRerank = () => {
Expand Down Expand Up @@ -31,7 +32,7 @@ const LaunchRerank = () => {
try {
setIsCallingApi(true)

const response = await fetch(
const response = await fetcher(
`${endPoint}/v1/model_registrations/rerank`,
{
method: 'GET',
Expand All @@ -41,7 +42,7 @@ const LaunchRerank = () => {
const registrations = await response.json()
const newRegistrationData = await Promise.all(
registrations.map(async (registration) => {
const desc = await fetch(
const desc = await fetcher(
`${endPoint}/v1/model_registrations/rerank/${registration.model_name}`,
{
method: 'GET',
Expand Down
3 changes: 2 additions & 1 deletion xinference/web/ui/src/scenes/launch_model/modelCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import React, { useContext, useEffect, useState } from 'react'
import { v1 as uuidv1 } from 'uuid'

import { ApiContext } from '../../components/apiContext'
import fetcher from '../../components/fetcher'

const CARD_HEIGHT = 350
const CARD_WIDTH = 270
Expand Down Expand Up @@ -104,7 +105,7 @@ const ModelCard = ({ url, modelData }) => {
}

// First fetch request to initiate the model
fetch(url + '/v1/models', {
fetcher(url + '/v1/models', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
3 changes: 2 additions & 1 deletion xinference/web/ui/src/scenes/launch_model/rerankCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, { useContext, useEffect, useState } from 'react'
import { v1 as uuidv1 } from 'uuid'

import { ApiContext } from '../../components/apiContext'
import fetcher from '../../components/fetcher'

const CARD_HEIGHT = 270
const CARD_WIDTH = 270
Expand Down Expand Up @@ -32,7 +33,7 @@ const RerankCard = ({ url, modelData }) => {
}

// First fetch request to initiate the model
fetch(url + '/v1/models', {
fetcher(url + '/v1/models', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
5 changes: 3 additions & 2 deletions xinference/web/ui/src/scenes/register_model/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import React, { useContext, useEffect, useState } from 'react'

import { ApiContext } from '../../components/apiContext'
import ErrorMessageSnackBar from '../../components/errorMessageSnackBar'
import fetcher from '../../components/fetcher'
import Title from '../../components/Title'
import { useMode } from '../../theme'

Expand Down Expand Up @@ -78,7 +79,7 @@ const RegisterModel = () => {

useEffect(() => {
const getBuiltInPromptStyles = async () => {
const response = await fetch(endPoint + '/v1/models/prompts', {
const response = await fetcher(endPoint + '/v1/models/prompts', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -171,7 +172,7 @@ const RegisterModel = () => {
}

try {
const response = await fetch(endPoint + '/v1/model_registrations/LLM', {
const response = await fetcher(endPoint + '/v1/model_registrations/LLM', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down
12 changes: 6 additions & 6 deletions xinference/web/ui/src/scenes/running_models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { DataGrid } from '@mui/x-data-grid'
import React, { useContext, useEffect, useState } from 'react'

import { ApiContext } from '../../components/apiContext'
import fetcher from '../../components/fetcher'
import Title from '../../components/Title'

const RunningModels = () => {
Expand Down Expand Up @@ -36,7 +37,7 @@ const RunningModels = () => {
])
} else {
setIsUpdatingModel(true)
fetch(`${endPoint}/v1/models/`, {
fetcher(`${endPoint}/v1/models/`, {
method: 'GET',
})
.then((response) => response.json())
Expand Down Expand Up @@ -153,15 +154,14 @@ const RunningModels = () => {
}

setIsCallingApi(true)

fetch(openUrl, {
fetcher(openUrl, {
method: 'HEAD',
})
.then((response) => {
if (response.status === 404) {
// If web UI doesn't exist (404 Not Found)
console.log('UI does not exist, creating new...')
return fetch(gradioUrl, {
return fetcher(gradioUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand Down Expand Up @@ -231,7 +231,7 @@ const RunningModels = () => {
return
}
setIsCallingApi(true)
fetch(closeUrl, {
fetcher(closeUrl, {
method: 'DELETE',
})
.then((response) => {
Expand Down Expand Up @@ -328,7 +328,7 @@ const RunningModels = () => {
return
}
setIsCallingApi(true)
fetch(closeUrl, {
fetcher(closeUrl, {
method: 'DELETE',
})
.then((response) => {
Expand Down
Loading