Add User-Agent header (#2602)
This commit is contained in:
		
							parent
							
								
									921609cab1
								
							
						
					
					
						commit
						5b039a1bee
					
				
					 5 changed files with 12 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -7,6 +7,7 @@ import { URL } from 'url';
 | 
			
		|||
import * as yaml from 'js-yaml';
 | 
			
		||||
import { Source, Mixin } from './types';
 | 
			
		||||
import isUrl = require('is-url');
 | 
			
		||||
const pkg = require('../../package.json');
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Path of configuration directory
 | 
			
		||||
| 
						 | 
				
			
			@ -43,6 +44,7 @@ export default function load() {
 | 
			
		|||
	mixin.stats_url = `${mixin.scheme}://${mixin.host}/stats`;
 | 
			
		||||
	mixin.status_url = `${mixin.scheme}://${mixin.host}/status`;
 | 
			
		||||
	mixin.drive_url = `${mixin.scheme}://${mixin.host}/files`;
 | 
			
		||||
	mixin.user_agent = `Misskey/${pkg.version} (${config.url})`;
 | 
			
		||||
 | 
			
		||||
	if (config.localDriveCapacityMb == null) config.localDriveCapacityMb = 256;
 | 
			
		||||
	if (config.remoteDriveCapacityMb == null) config.remoteDriveCapacityMb = 8;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -114,6 +114,7 @@ export type Mixin = {
 | 
			
		|||
	status_url: string;
 | 
			
		||||
	dev_url: string;
 | 
			
		||||
	drive_url: string;
 | 
			
		||||
	user_agent: string;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
export type Config = Source & Mixin;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -27,6 +27,7 @@ export default (user: ILocalUser, url: string, object: any) => new Promise((reso
 | 
			
		|||
		method: 'POST',
 | 
			
		||||
		path: pathname + search,
 | 
			
		||||
		headers: {
 | 
			
		||||
			'User-Agent': config.user_agent,
 | 
			
		||||
			'Content-Type': 'application/activity+json',
 | 
			
		||||
			'Digest': `SHA-256=${hash}`
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,7 @@
 | 
			
		|||
import * as request from 'request-promise-native';
 | 
			
		||||
import * as debug from 'debug';
 | 
			
		||||
import { IObject } from './type';
 | 
			
		||||
//import config from '../../config';
 | 
			
		||||
import config from '../../config';
 | 
			
		||||
 | 
			
		||||
const log = debug('misskey:activitypub:resolver');
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -51,6 +51,7 @@ export default class Resolver {
 | 
			
		|||
		const object = await request({
 | 
			
		||||
			url: value,
 | 
			
		||||
			headers: {
 | 
			
		||||
				'User-Agent': config.user_agent,
 | 
			
		||||
				Accept: 'application/activity+json, application/ld+json'
 | 
			
		||||
			},
 | 
			
		||||
			json: true
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -34,7 +34,12 @@ export default async (url: string, user: IUser, folderId: mongodb.ObjectID = nul
 | 
			
		|||
	// write content at URL to temp file
 | 
			
		||||
	await new Promise((res, rej) => {
 | 
			
		||||
		const writable = fs.createWriteStream(path);
 | 
			
		||||
		request(url)
 | 
			
		||||
		request({
 | 
			
		||||
			url,
 | 
			
		||||
			headers: {
 | 
			
		||||
				'User-Agent': config.user_agent
 | 
			
		||||
			}
 | 
			
		||||
		})
 | 
			
		||||
			.on('error', rej)
 | 
			
		||||
			.on('end', () => {
 | 
			
		||||
				writable.close();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue